Exemple #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** A First Look at Structures *****\n");

            // Point myPoint;
            // myPoint.X = 349;
            // myPoint.Y = 76;
            // myPoint.Display();
            //
            // myPoint.Increment();
            // myPoint.Display();
            // Console.ReadLine();
            //
            // Point p1 = new Point();
            // p1.Display();
            // Console.ReadLine();
            //
            // Point p2 = new Point(50,60);
            // p2.Display();
            //
            // Console.ReadLine();
            //
            // PointWithReadOnly p3 = new PointWithReadOnly(50,60,"Point w/RO");
            // p3.Display();
            // p3.X = 120;
            // p3.Y = 340; // readonly can be assigned only in constructor
            // p3.Name = "New Name"; // readonly can be assigned only in constructor

            var s = new DisposableRefStruct(50, 60);

            s.Display();
            s.Dispose();
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** A First Look at Structures *****\n");
            // Create an initial Point.
            Point myPoint;

            myPoint.X = 349;
            myPoint.Y = 76;
            myPoint.Display();
            // Adjust the X and Y values.
            myPoint.Increment();
            myPoint.Display();
            Console.ReadLine();
            // Call custom constructor.
            Point p2 = new Point(50, 60);

            // Prints X=50,Y=60.
            p2.Display();
            PointWithReadOnly p3 =
                new PointWithReadOnly(50, 60, "Point w/RO");

            p3.Display();
            var s = new DisposableRefStruct(50, 60);

            s.Display();
            s.Dispose();
        }