using System; using System.Linq; using System.Reflection; using Stuglxt_Models; namespace ConsoleApp1 { public delegate int MydeleGate(int a, int b); class Program { static void Main(string[] args) { #region 委托与多播 //Student student = new Student(); //MydeleGate mydeleGate =(a,b)=> a+b; //dynamic result = mydeleGate(5, 2); //Console.WriteLine(result); //mydeleGate += student.Add; //result = mydeleGate==null? mydeleGate+=student.Sub:mydeleGate+=student.Add; //result=result(1, 2); //Console.WriteLine(result); #endregion #region 数组linq查询方法 //linq //int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //var item = from num in nums where num % 2 == 0 orderby num descending select num; //foreach (var i in item) { // Console.WriteLine(i); //} #endregion #region 字符串linq查询方法 //string[] nums = { "张**", "年*", "陈*", "刘*", "王*", "韩*", "吴*","年*" }; //var list = nums.Where(item => item.Length == 2).Select(item => item).GroupBy(item => item.Substring(0, 1)); //foreach (var item in list) { // Console.WriteLine("-----------"); // Console.WriteLine("分组字段:{0}",item.Key); // foreach (var k in item) { // Console.WriteLine(k); // } //} #endregion #region linq高级查询方法 int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //var Count = nums.Count();//获取元素个数 //Console.WriteLine(Count); int[] nums0 = { 1, 2, 2, 4, 4, 7, 7, 8, 9, 10 }; //var list = nums.Skip(1).Take(3);//指定列跳过和选择指定项个数输 //var list = nums.SkipWhile(i => i % 3 != 0).TakeWhile(i => i % 2 != 0);//跳过符合条件的数列和选取符合条件的数列 var list = nums0.Distinct();//去重复 foreach (var i in list) { Console.WriteLine(i); } #endregion Console.ReadKey(); } class Student { public int Add(int a, int b) => a + b; public int Sub(int a, int b) => a - b; } } }
我的平时练习代码
原文:https://www.cnblogs.com/sandaman2019/p/11387693.html