LINQ (Language Integrated Query) was officially introduced in .NET 3.5. Here is a simple example
string[] currentVideoGames = {"Morrowind",
"BioShock"};
// Build a query expression to represent the items in the
array
// that
have more than 6 letters.
IEnumerable<string> subset = from g in
currentVideoGames
where
g.Length > 6
orderby
g
select
g;
Some Internals:
Linq
internally converts Linq Queries to some pre-build generics.
IEnumerable<int> subset = from i in numbers where i
< 10 select i;
Is Converted
to:
IEnumerable<int> subset = Enumerable.Where<int>(numbers,
(i => (i<10)) );
Capturing and saving results of LINQ:
int[]
subsetAsIntArray =
(from
i in numbers where i < 10 select i).ToArray<int>();
//It's
Enumerable's extension method.
Filtering collection based on type:
ArrayList
myStuff = new ArrayList();
myStuff.AddRange(new
object[] { 10, 400, false, new Car(), "string data" });
IEnumerable<int>
myInts = myStuff.OfType<int>();