static void Main(string[] args) {
            Rectangle r = new Rectangle(15, 4);
            Console.WriteLine(r);
            r.Draw();

            Console.WriteLine();

            Square s = (Square)r;
            Console.WriteLine(s);
            s.Draw();

            Console.WriteLine();
            Rectangle r2 = new Rectangle(4, 2);
            DrawSquare((Square)r2);


            //conversion to and from int
            Square sq2 = (Square)90;
            int side = (int)sq2;

            //implicit conversion;

            Rectangle rImpl = sq2;
            Console.WriteLine(rImpl);

            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Conversions *****\n");

            // Make a Rectangle.
            Rectangle r = new Rectangle(15, 4);
            Console.WriteLine(r.ToString());
            r.Draw();

            Console.WriteLine();

            // Convert r into a Square, based on the height of the Rectangle.
            Square s = (Square)r;
            Console.WriteLine(s.ToString());
            s.Draw();
            Console.ReadLine();
        }
Beispiel #3
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Conversions *****\n");

            // Make a Rectangle.
            Rectangle r = new Rectangle(15, 4);
            Console.WriteLine(r.ToString());
            r.Draw();

            Console.WriteLine();

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

            // Convert Rectangle to Square to invoke method.
            Rectangle rect = new Rectangle(10, 5);
            DrawSquare((Square)rect);
            Console.WriteLine();

            // Converting an int to a Square.
            Square sq2 = (Square)90;
            Console.WriteLine("sq2 = {0}", sq2);

            // Converting a Square to a int.
            int side = (int)sq2;
            Console.WriteLine("Side length of sq2 = {0}", side);
            Console.WriteLine();

            Square s3 = new Square();
            s3.Length = 83;

            // Attempt to make an implicit cast?
            Rectangle rect2 = s3;

            Console.ReadLine();
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Conversions *****\n");
            Rectangle r = new Rectangle(15, 4);
            Console.WriteLine(r.ToString());
            r.Draw();
            Console.WriteLine();

            Square s = (Square) r;
            Console.WriteLine(s.ToString());
            s.Draw();
            Console.WriteLine();

            Rectangle rect = new Rectangle(10, 5);
            DrawSquare((Square) rect);
            Console.WriteLine();

            Square sqs = (Square) 90;
            Console.WriteLine("sq2 = {0}\n", sqs);

            int side = (int) sqs;
            Console.WriteLine("Side length of sqs = {0}\n", side);

            Square s3 = new Square();
            s3.Length = 7;
            Rectangle rect2 = s3;
            Console.WriteLine("rect2 = {0}", rect2);
            DrawSquare(s3);
            Console.WriteLine();

            Square s4 = new Square();
            s4.Length = 3;
            Rectangle rect3 = (Rectangle) s4;
            Console.WriteLine("rect3 = {0}", rect3);

            Console.ReadLine();
        }