static void NotMain() { MyBol Bol = (x, y) => x == y; MyBol_2 Bol_2 = (x, s) => s.Length > x; calculator C = (X, Y) => X * Y; VS S = () => Console.Write("我是无参数Labada表达式"); // int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int oddNumbers = numbers.Count(n => n % 2 == 1); // List <People> people = LoadData();//初始化 // 分解 // 自己建的委托 delegate bool MyDele(People p); // 使用委托 MyDele myDele = p => p.age > 20; // C#内置泛型委托 delegate TResult System.Func<int T, out TResult>(T arg) Func <People, bool> predicate = p => p.age > 20; IEnumerable <People> results2 = people.Where(predicate); // 委托的实例化:使用匿名方法 // < 委托类型 > < 实例化名 >= delegate (< 函数参数 >){ 函数体}; Func <People, bool> predicate2 = delegate(People p) { return(p.age > 20); }; IEnumerable <People> results4 = people.Where(predicate2); IEnumerable <People> results = people.Where(delegate(People p) { return(p.age > 20); }); // 更简便的写法 IEnumerable <People> results3 = people.Where(p => p.age > 20); }
void Start() { MyBol Bol = (x, y) => x == y; MyBol_2 Bol_2 = (x, s) => s.Length > x; calculator C = (X, Y) => X * Y; VS S = () => Debug.Log("我是无参数Labada表达式"); // int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int oddNumbers = numbers.Count(n => n % 2 == 1); // List <People> people = LoadData();//初始化 IEnumerable <People> results = people.Where(delegate(People p) { return(p.age > 20); }); }
static void Main(string[] args) { MyBol Bol = (x, y) => x == y; MyBol_2 Bol_2 = (x, s) => s.Length > x; calculator C = (X, Y) => X * Y; VS S = () => Console.Write("我是无参数lambda表达式"); // Console.Write("无参数"); //Console.ReadLine(); // int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; int oddNumbers = numbers.Count(n => n % 2 == 1); //奇数 // List <People> people = LoadData(); //初始化 IEnumerable <People> results = people.Where(delegate(People p) { return(p.age > 20); }); //Console.Write(); Console.ReadLine(); }