using System; using System.Collections.Generic; using System.Linq; namespace Commission { class Program { static void Main(string[] args) { int[] arrInt = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; //var result = Common.FilterArrayOfInts(arrInt, Application.IsOdd); //var result = Common.FilterArrayOfInts(arrInt, delegate (int i) { return (i & 1) == 1; }); //var result = Common.FilterArrayOfInts(arrInt, i => (i & 1) == 1); var result = arrInt.Where(i => (i & 1) == 1); foreach (int i in result) { Console.WriteLine(i); } Console.ReadLine(); } } class Common { public delegate bool IntFilter(int i); public static List<int> FilterArrayOfInts(int[] ints, IntFilter filter) { List<int> aList = new List<int>(); foreach (int i in ints) { if (filter(i)) { aList.Add(i); } } return aList; } } class Application { public static bool IsOdd(int i) { return (i & 1) == 1; } public static bool IsEven(int i) { return (i & 1) == 0; } } }
记录C#委托应用1
猜你喜欢
转载自www.cnblogs.com/chenbingquan/p/10803541.html
今日推荐
周排行