Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            string input;
            double length;

            do
            {
                Console.WriteLine("Enter a length: ");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out length));

            double width;

            do
            {
                Console.WriteLine("Enter a width: ");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out width));

            var rectangle = new Rectangle()
            {
                Length = length,
                Width  = width
            };

            rectangle.PrintRectangle();

            double radius;

            do
            {
                Console.WriteLine("enter a radius: ");
                input = Console.ReadLine();
            }while(!double.TryParse(input, out radius));

            ColorCircle colorCircle = new ColorCircle
            {
                Radius = radius,
                Color  = "black"
            };

            Console.WriteLine(colorCircle.GetPerimeter());
            Console.WriteLine(ShapeDetails(circle));


            // C# has something called "out" parameters
            // an out parameter cannot have a value before you pass it
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            double length;
            string input;

            do
            {
                Console.WriteLine("Enter a length:");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out length));
            double width;

            do
            {
                Console.WriteLine("Enter a width:");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out width));

            // C# has something called "out" parameters
            // an out parameter cannot have a value before you pass it
            // the method gets that exact variable and fills in its value

            // similar to collection initializer, we have property initializer

            var rectangle = new Rectangle
            {
                Length = length,
                Width  = width
            };

            // PrintRectangle(rectangle);
            rectangle.PrintRectangle();

            double radius;

            do
            {
                Console.WriteLine("Enter a radius:");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out radius));

            ColorCircle colorCircle = new ColorCircle(radius: radius, color: "black");

            Console.WriteLine(colorCircle.GetPerimeter());

            Console.WriteLine(ShapeDetails(colorCircle));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            double length;
            string input;

            do
            {
                Console.WriteLine("Enter a Length: ");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out length));

            double width;

            do
            {
                Console.WriteLine("Enter a Width: ");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out width));

            var rectangle = new Rectangle
            {
                Length = length,
                Width  = width
            };

            rectangle.PrintRectangle();

            double radius;

            do
            {
                Console.WriteLine("Enter a radius: ");
                input = Console.ReadLine();
            } while (!double.TryParse(input, out radius));

            ColorCircle colorCircle = new ColorCircle(radius: radius, colorCircle: "black");

            Console.WriteLine(colorCircle.GetPerimeter());

            Console.WriteLine(ShapeDetails(colorCircle));
        }