Ejemplo n.º 1
0
            static void Main(string[] args)
            {
                TwoDPoint pointA = new TwoDPoint(3, 4);
                TwoDPoint pointB = new TwoDPoint(3, 4);
                int       i      = 5;

                // Compare using virtual Equals, static Equals, and == and != operators.
                // True:
                Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB));
                // True:
                Console.WriteLine("pointA == pointB = {0}", pointA == pointB);
                // True:
                Console.WriteLine("Object.Equals(pointA, pointB) = {0}", Object.Equals(pointA, pointB));
                // False:
                Console.WriteLine("pointA.Equals(null) = {0}", pointA.Equals(null));
                // False:
                Console.WriteLine("(pointA == null) = {0}", pointA == null);
                // True:
                Console.WriteLine("(pointA != null) = {0}", pointA != null);
                // False:
                Console.WriteLine("pointA.Equals(i) = {0}", pointA.Equals(i));
                // CS0019:
                // Console.WriteLine("pointA == i = {0}", pointA == i);

                // Compare unboxed to boxed.
                System.Collections.ArrayList list = new System.Collections.ArrayList();
                list.Add(new TwoDPoint(3, 4));
                // True:
                Console.WriteLine("pointE.Equals(list[0]): {0}", pointA.Equals(list[0]));


                // Compare nullable to nullable and to non-nullable.
                TwoDPoint?pointC = null;
                TwoDPoint?pointD = null;

                // False:
                Console.WriteLine("pointA == (pointC = null) = {0}", pointA == pointC);
                // True:
                Console.WriteLine("pointC == pointD = {0}", pointC == pointD);

                TwoDPoint temp = new TwoDPoint(3, 4);

                pointC = temp;
                // True:
                Console.WriteLine("pointA == (pointC = 3,4) = {0}", pointA == pointC);

                pointD = temp;
                // True:
                Console.WriteLine("pointD == (pointC = 3,4) = {0}", pointD == pointC);

                // Keep the console window open in debug mode.
                System.Console.WriteLine("Press any key to exit.");
                System.Console.ReadKey();
            }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            TwoDPoint pointA = new TwoDPoint(3, 4);
            TwoDPoint pointB = new TwoDPoint(3, 4);
            int       i      = 5;

            // True:
            Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB));
            // True:
            Console.WriteLine("pointA == pointB = {0}", pointA == pointB);
            // True:
            Console.WriteLine("object.Equals(pointA, pointB) = {0}", object.Equals(pointA, pointB));
            // False:
            Console.WriteLine("pointA.Equals(null) = {0}", pointA.Equals(null));
            // False:
            Console.WriteLine("(pointA == null) = {0}", pointA == null);
            // True:
            Console.WriteLine("(pointA != null) = {0}", pointA != null);
            // False:
            Console.WriteLine("pointA.Equals(i) = {0}", pointA.Equals(i));
            // CS0019:
            // Console.WriteLine("pointA == i = {0}", pointA == i);

            // Compare unboxed to boxed.
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            list.Add(new TwoDPoint(3, 4));
            // True:
            Console.WriteLine("pointA.Equals(list[0]): {0}", pointA.Equals(list[0]));

            // Compare nullable to nullable and to non-nullable.
            TwoDPoint?pointC = null;
            TwoDPoint?pointD = null;

            // False:
            Console.WriteLine("pointA == (pointC = null) = {0}", pointA == pointC);
            // True:
            Console.WriteLine("pointC == pointD = {0}", pointC == pointD);

            TwoDPoint temp = new TwoDPoint(3, 4);

            pointC = temp;
            // True:
            Console.WriteLine("pointA == (pointC = 3,4) = {0}", pointA == pointC);

            pointD = temp;
            // True:
            Console.WriteLine("pointD == (pointC = 3,4) = {0}", pointD == pointC);

            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Ejemplo n.º 3
0
            static void Main(string[] args)
            {
                ThreeDPoint pointA = new ThreeDPoint(3, 4, 5);
                ThreeDPoint pointB = new ThreeDPoint(3, 4, 5);
                ThreeDPoint pointC = null;
                int         i      = 5;

                Console.WriteLine("pointA.Equals(pointB) = {0}", pointA.Equals(pointB));
                Console.WriteLine("pointA == pointB = {0}", pointA == pointB);
                Console.WriteLine("null comparison = {0}", pointA.Equals(pointC));
                Console.WriteLine("Compare to some other type = {0}", pointA.Equals(i));

                TwoDPoint pointD = null;
                TwoDPoint pointE = null;

                Console.WriteLine("Two null TwoDPoints are equal: {0}", pointD == pointE);

                pointE = new TwoDPoint(3, 4);
                Console.WriteLine("(pointE == pointA) = {0}", pointE == pointA);
                Console.WriteLine("(pointA == pointE) = {0}", pointA == pointE);
                Console.WriteLine("(pointA != pointE) = {0}", pointA != pointE);

                System.Collections.ArrayList list = new System.Collections.ArrayList();
                list.Add(new ThreeDPoint(3, 4, 5));
                Console.WriteLine("pointE.Equals(list[0]): {0}", pointE.Equals(list[0]));

                // Keep the console window open in debug mode.
                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }