LINQ让数据处理变的更简单
委托
static void Main(string[] args)
{
D1 d = F1;
d();
D2 d2 =Add;
Console.WriteLine(d2(1));
//int:参数,int返回值
Func<int,int> f1 = Add;
Console.WriteLine(f1(1);
}
static void F1()
{
Console.WriteLine("我是F1");
}
static int Add(int a)
{
return a;
}
//委托
delegate void D1();
delegate int D2(int i);
匿名委托
static void Main(string[] args)
{
Action<string,int> f2 = delegate(string n,int i)
{
Console.WriteLine($"n={n},i={i}");
};
f2("zbt",18);
Func<int,int,int> f3 = delegate(int i,int j)
{
return i + j;
}
Console.writeLine(f3(3,5));
}
lamdba表达式--匿名委托
Func<int,int,int> f4 = (i, j) => {return i + j;}
//只有一行
Func<int,int,int> f4 = (i, j) => i + j;
Action f1 = () => Console.WriteLine("f1");
//一个参数
Action<int> a2 = i => Console.WriteLine(i);
LINQ
List<Student> list = new List<Student>();
list.Add(new Student(Age = 28));
list.Add(new Student(Age = 21));
list.Add(new Student(Age = 18));
list.Add(new Student(Age = 19));
list.Add(new Student(Age = 50));
list.Add(new Student(Age = 27));
//查询
IEnumerable<Student> items1 = list.where(e => e.Age > 20);
foreach(Stduent e in items)
{
Console.Write(e);
}
//行数
int a = list.Count(e => e.Age > 20);
//是否至少有一条数据
bool b = list.Any(e => e.Age = 20);