using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/*
* 1、Linq查询结果有两种类型:一个是枚举,一个是标量(scalar)
*/
namespace Linq三种查询
{
class Program
{
static void Main(string[] args)
{
int[] numbers = { 12,23,34,45,56,67,78,89};
var numbersQuery = from n in numbers
where n > 10
select n;
var numberMothod = numbers.Where(n =>n >10);
int count = (from n in numbers where n > 10
select n).Count();
foreach (var x in numbersQuery)
Console.Write("{0}\t",x);
Console.WriteLine();
foreach (var x in numberMothod)
Console.Write("{0}\t", x);
Console.WriteLine();
Console.WriteLine(count);
Console.ReadKey();
}
}
}
时间: 2024-10-25 04:22:52