概念:
public delegate int DelCompare<T>(T o1,T o2); class Program { static void Main(string[] args) { int[] nums = { 2,5,6,9,1,5,8}; int max = GetMax<int>(nums, delegate(int max1,int num) { return max1 - num; }); int max3 = GetMax<int>(nums,Compare); Console.WriteLine(max); Console.ReadKey(); } public static int Compare(int o1,int o2) { return o1 - o2; } public static T GetMax<T>(T[] nums, DelCompare<T> del) { T max = nums[0]; for (int i = 0; i < nums.Length; i++) { if (del(max, nums[i]) < 0) { max = nums[i]; } } return max; } }
原文:http://www.cnblogs.com/genesis/p/4888276.html