Here I will give one very simple linq sample code.
A query that will return each of the items in the people
List
collection by aliasing the people
collection with a variable p
and then selecting p
(p
is of type string
remember as the people
List
is a collection of immutable string
objects).
You may notice that query is of type IEnumerable
- this is because we know that query will hold an enumeration of type string
. When we foreach
through the query the GetEnumerator
of query is invoked.
protected void Page_Load(object sender, EventArgs e)
{
List
"Sen", "Paulose", "Thomas", "Raju",
"Anil", "Shyam", "Saidwin"
};
IEnumerable
foreach (string person in query)
{
Response.Write(person);
}
}
: