using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int[] nums = new int[] { 10, 2, 3, 100, 1, 5, 17, 82, 22, 3 };
var result = from m in nums where m >= 10 select m;
foreach (var v in result)
{
Console.WriteLine("v:" + v + " ");
}
Console.WriteLine("\n");
//使用Lambda 表达式进行Linq查询
var result2 = nums.Where(m => m >= 10);
foreach (var v in result2)
{
Console.WriteLine("v2:" + v + " ");
}
List<People> mans = new List<People>();
mans.Add(new People { id = 10, sex = true, name = "小王", birthday = Convert.ToDateTime("1994-1-1") });
mans.Add(new People { id = 11, sex = false, name = "小张", birthday = Convert.ToDateTime("1954-1-1") });
mans.Add(new People { id = 12, sex = true, name = "小明", birthday = Convert.ToDateTime("1993-1-1") });
mans.Add(new People { id = 13, sex = false, name = "小红", birthday = Convert.ToDateTime("1974-1-1") });
var resultMan = from man in mans where man.id < 11 && man.sex select man;
foreach (var v in resultMan)
{
Console.WriteLine("v:" + v.id + " name :" + v.name);
}
Console.Read();
}
}
class People
{
public string name { get; set; }
public int id { get; set; }
public bool sex { get; set; }
public DateTime birthday { get; set; }
public int GetAge()
{
return DateTime.Now.Year - birthday.Year;
}
}
}