奇偶数判断:委托思维
namespace delegateLambda1 { class Program { delegate bool numberChoose(int i); static void Main(string[] args) { List<int> iList = new List<int>(10){1,2,3,4,5,6,7,8,9,10}; numberChoose nc1 = i => (i % 2 == 1); numberChoose nc2 = i => (i % 2 == 0); numberChoose nc3 = i => (i % 5 == 0); display(iList, nc1); display(iList, nc2); display(iList, nc3); Console.ReadLine(); } static void display(List<int> ilist, numberChoose nc) { List<int> result = new List<int>(); foreach (int i in ilist) { if (nc(i)) { result.Add(i); } } foreach (int i in result) { Console.Write(i + ""); } Console.WriteLine(); } } }
有了他,编程思想要变塞,好OOP
浙公网安备 33010602011771号