LINQ to Objects is a set of extension methods in the System.Linq namespace of C# that provides a powerful and easy way to query data collections. Here is an example of how to use LINQ to Objects to query a list of integers:
main.cs654 chars26 linesIn this example, we create a list of integers and query it to get the even numbers using LINQ. The where clause filters out the odd numbers, and select projects the result to a sequence of even numbers. The result is an IEnumerable<int> that can be iterated over or converted to other data types. Note that you can also use method syntax to achieve the same result, as shown in the commented line.
gistlibby LogSnag