예제 #1
0
        // NULL
        public void WorkingWithNull()
        {
            PointC p = null;

            Console.WriteLine(p == null); // => true

            // The following oline generates a runtime error
            // (a NullReferenceException is throw):
            Console.WriteLine(p.X);

            // In contrast, a value type cannot ordinarily have a null value:
            // PointS p2 = null; // Compile-time error
            // int x = null; // Compile-time error
        }
예제 #2
0
        // REFERENCE TYPES
        public void ReferenceTypes()
        {
            PointC p1 = new PointC();

            p1.X = 7;

            PointC p2 = p1;          // Copies p1 reference

            Console.WriteLine(p1.X); // => 7
            Console.WriteLine(p2.X); // => 7

            p1.X = 9;                // Change p1.X

            Console.WriteLine(p1.X); // => 9
            Console.WriteLine(p2.X); // => 9
        }