// MyFunc - use the methods provided by the ICompare interface // to display the value of two objects and then an indication // of which is greater (according to the object itself) public static void MyFunc(ICompare ic1, ICompare ic2) { Console.WriteLine("The value of ic1 is {0} and ic2 is {1}", ic1.GetValue(), ic2.GetValue()); string s; switch (ic1.CompareTo(ic2)) { case 0: s = "is equal to"; break; case -1: s = "is less than"; break; case 1: s = "is greater than"; break; default: s = "something messed up"; break; } Console.WriteLine( "The objects themselves think that ic1 {0} ic2", s); }
/// <summary> /// BubbleSort /// </summary> /// <param name="array">array with 2 measure</param> public static void BubbleSort(int[][] array, ICompare compare) { for (int i = 0; i < array.Length - 1; i++) { for (int j = 0; j < array.Length - 1 - i; j++) { if (compare.CompareTo(array[j], array[j + 1]) > 0) { Swap(ref array[j], ref array[j + 1]); } } } }