Пример #1
0
        static void DoStruct()
        {
            AddHeading("Structures");
            // Structs are value types; Classes are reference types
            // Structs exist only on the stack, whereas class objects reference
            // their entities on the heap

            Graph pos1 = new Graph(12, 5);
            Graph pos2 = new Graph(8, 11);

            Console.WriteLine(">> Initial Values:");
            Console.WriteLine("Position 1: [{0},{1}]", pos1.xPos, pos1.yPos);
            Console.WriteLine("Position 2: [{0},{1}]", pos2.xPos, pos2.yPos);

            // This assigns values of "pos1" to same values of "pos2", but as a struct
            // is not a reference type it does not point to "pos2", unlike a class type
            pos1 = pos2;
            Console.WriteLine(">> After: pos1 = pos2");
            Console.WriteLine("Position 1: [{0},{1}]", pos1.xPos, pos1.yPos);
            Console.WriteLine("Position 2: [{0},{1}]", pos2.xPos, pos2.yPos);

            pos1.xPos = 24;
            Console.WriteLine(">> After: pos1.xPos = 24");
            Console.WriteLine("Position 1: [{0},{1}]", pos1.xPos, pos1.yPos);
            Console.WriteLine("Position 2: [{0},{1}]", pos2.xPos, pos2.yPos);

            pos1.Transpose();
            Console.WriteLine(">> After: pos1.Transpose()");
            Console.WriteLine("Position 1: [{0},{1}]", pos1.xPos, pos1.yPos);
            Console.WriteLine("Position 2: [{0},{1}]", pos2.xPos, pos2.yPos);

            int day   = InputInteger("Input date day", 1, 31);
            int month = InputInteger("Input date month number", 1, 12);
            int year  = InputInteger("Input the year", 1950, 2100);

            Console.WriteLine(">> Input date: {0:D2}/{1:D2}/{2}", day, month, year);
            MyDate xdate = new MyDate(day, month, year);

            xdate.ShowDate();
        }