//筛选
List<Person> persons = PersonsList();
persons = persons.Where(p => p.Age > 6).ToList(); //所有Age>6的Person的集合
persons = persons.Where(p => p.Name.Contains("儿子")).ToList(); //所有Name包含儿子的Person的集合
//委托 逛超市
delegate int GuangChaoshi(int a);
static void Main(string[] args)
{
// GuangChaoshi gwl = JieZhang;
GuangChaoshi gwl = p => p + 10;
Console.WriteLine(gwl(10) + ""); //打印20,表达式的应用
Console.ReadKey();
}
//委托 逛超市 带参数
delegate int GuangChaoshi(int a,int b);
static void Main(string[] args)
{
GuangChaoshi gwl = (p,z) => z-(p + 10);
Console.WriteLine(gwl(10,100) + ""); //打印80,z对应参数b,p对应参数a
Console.ReadKey();
}
//Func<T>委托
static void Main(string[] args)
{
Func<int, string> gwl = p => p + 10 + "--返回类型为string";
Console.WriteLine(gwl(10) + ""); //打印‘20--返回类型为string’,z对应参数b,p对应参数a
Console.ReadKey();
}
//Func<T>委托
static void Main(string[] args)
{
Func<int, int, bool> gwl = (p, j) =>
{
if (p + j == 10)
{
return true;
}
return false;
};
Console.WriteLine(gwl(5,5) + ""); //打印‘True’,z对应参数b,p对应参数a
Console.ReadKey();
}
//Action委托
public class Test
{
static public Action A;
static public Action<int> B;
static public Action<int, string> C;
static public Action<int, string, int> D;
static public Action<int, string, int, string> E;
static void Main()
{
A = () =>
{
Console.WriteLine("I'm A ");
};
B = (i) =>
{
Console.WriteLine("I'm B " + i);
};
C = (i, s) =>
{
Console.WriteLine("I'm C " + i + " " + s) ;
} ;
D = (i, s, j) =>
{
Console.WriteLine("I'm D " + i + " " + s + " " + j) ;
} ;
E = (i, s, j, t) =>
{
Console.WriteLine("I'm E " + i + " " + s + " " + j + " " + t);
};
A();
B(1);
C(1, "a");
D(1, "a", 2);
E(1, "a", 2, "b");
Console.ReadKey();