int[] intArray = new int[] { 10, 3, 4, 16, 78, 14 };
string[] strArray = new string[] { "hello world", "doomsday", "china" };
IEnumerable<int> result = from n in intArray //查询语法
where n < 20
select n;
foreach (var x in result)
{
Console.WriteLine("{0}", x);
}
var nums = intArray.Where(x => x < 20); //方法语法
int intCount = (from n in intArray //两种形式的组合
where n <= 20
select n).Count();
IEnumerable<string> strResult = from n in strArray
where n == "hello world" || n == "doomsday"
select n;
foreach (string y in strResult)
{
Console.WriteLine(y);
} 作者: 许庭洲 时间: 2012-10-13 20:06
值得学习ing!