LINQ,语言集成查询(Language Integrated Query)是一组用于C#语言的扩展。
LINQ的查询操作分为三步:
1.获取数据源
2.创建查询
3.执行查询
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { //获取数据源 int[] numbers = new int[7]{ 0, 1, 2, 3, 4, 5, 6 }; //创建查询 var query = from num in numbers where (num % 2) == 0 select num; //执行查询 foreach (int num in query) { Console.WriteLine("{0}", num); } } } }