예제 #1
0
        static void Main(string[] args)
        {
            // Make a Rectangle.
            Rectangle r = new Rectangle(15, 4);

            Console.WriteLine(r.ToString());
            r.Draw();
            // Convert r into a Square,
            // based on the height of the Rectangle.
            Square s = (Square)r;

            Console.WriteLine(s.ToString());
            s.Draw();
            Console.ReadLine();
            // Implicit cast OK!
            Square s3 = new Square();

            s3.Length = 7;
            Rectangle rect2 = s3;

            Console.WriteLine("rect2 = {0}", rect2);
        }
예제 #2
0
        private static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Conversions *****\n");

            var r = new Rectangle(15, 4);

            Console.WriteLine(r.ToString());
            r.Draw();

            var s = (Square)r;

            Console.WriteLine(s.ToString());
            s.Draw();

            var sq2 = (Square)90;

            Console.WriteLine("sq2 = {0}", sq2);

            var side = (int)sq2;

            Console.WriteLine("Side length of sq2 = {0}", side);

            var s3 = new Square();

            s3.Length = 7;
            Rectangle rect2 = s3;

            Console.WriteLine("rect2 = {0}", rect2);

            var s4 = new Square();

            s4.Length = 3;
            Rectangle rect3 = (Rectangle)s4;

            Console.WriteLine("rect3 - {0}", rect3);

            Console.ReadLine();
        }
예제 #3
0
 static void Main(string[] args)
 {
     // Make a Rectangle.
     Rectangle r = new Rectangle(15, 4);
     Console.WriteLine(r.ToString());
     r.Draw();
     // Convert r into a Square,
     // based on the height of the Rectangle.
     Square s = (Square)r;
     Console.WriteLine(s.ToString());
     s.Draw();
     Console.ReadLine();
     // Implicit cast OK!
     Square s3 = new Square();
     s3.Length = 7;
     Rectangle rect2 = s3;
     Console.WriteLine("rect2 = {0}", rect2);
 }