Tutorial by Examples

LINQ requires .NET 3.5 or higher (or .NET 2.0 using LINQBridge). Add a reference to System.Core, if it hasn't been added yet. At the top of the file, import the namespace: C# using System; using System.Linq; VB.NET Imports System.Linq
In the following examples, we'll be using the following samples: List<Product> Products = new List<Product>() { new Product() { ProductId = 1, Name = "Book nr 1", Price = 25 }, new Product() { ProductId = 2, Name = "Book nr 2&quot...
Query syntax and method syntax are semantically identical, but many people find query syntax simpler and easier to read. Let’s say we need to retrieve all even items ordered in ascending order from a collection of numbers. C#: int[] numbers = { 0, 1, 2, 3, 4, 5, 6 }; // Query syntax: IEnumerab...
LINQ extension methods on IEnumerable<T> take actual methods1, whether anonymous methods: //C# Func<int,bool> fn = x => x > 3; var list = new List<int>() {1,2,3,4,5,6}; var query = list.Where(fn); 'VB.NET Dim fn = Function(x As Integer) x > 3 Dim list = New List F...

Page 1 of 1