// 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); }
override public int Compare(ICompare ic) { return(GetValue().CompareTo(ic.GetValue())); }