Example #1
0
    static void Main()
    {
        Console.WriteLine(10 < 20);
        Console.WriteLine(10.CompareTo(20));  // if 10 > 20 : -1, same : 0, 10 < 20 : 1

        string s1 = "AA", s2 = "BB";

        //        Console.WriteLine(s1 < s2); error, relational operator only used for numeric associate type
        Console.WriteLine(s1.CompareTo(s2)); // almost type, enable to compare

        Point p1 = new Point(1, 1);
        Point p2 = new Point(2, 2);

        Console.WriteLine(p1.CompareTo2(p2));


        // apply c# interface 2.0
        cPoint p3 = new cPoint(1, 1);
        cPoint p4 = new cPoint(2, 2);

        Console.WriteLine(p3.CompareTo(p4));
        object o2 = new cPoint(2, 2);

        Console.WriteLine(p3.CompareTo(o2));
    }