Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("**Ща бы с точками пофаниться**");
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();
            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Object Init Syntax *****\n");
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();
            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with Object Init Syntax *****");

            Point firstPoint = new Point();
            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            Point anotherPoint = new Point(20, 20);
            anotherPoint.DisplayStats();

            Point finalPoint = new Point { X = 30, Y = 30 };
            finalPoint.DisplayStats();

            Point goldPoint = new Point(PointColor.Gold) { X = 90, Y = 20 };
            goldPoint.DisplayStats();

            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point { X = 10, Y = 10 },
                BottomRight = new Point { X = 200, Y = 200 }
            };

            myRect.DisplayStats();

            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main( string[] args )
        {
            Console.WriteLine("***** Fun with Object Init Syntax *****\n");

            // Make a Point by setting each property manually.
            Point firstPoint = new Point();
            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            // Or make a Point via a custom constructor.
            Point anotherPoint = new Point(20, 20);
            anotherPoint.DisplayStats();

            // Or make a Point using object init syntax.
            Point finalPoint = new Point { X = 30, Y = 30 };
            finalPoint.DisplayStats();

            // Calling a more interesting custom constructor with init syntax.
            Point goldPoint = new Point(PointColor.Gold) { X = 90, Y = 20 };
            goldPoint.DisplayStats();

            // Create and initialize a Rectangle.
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point { X = 10, Y = 10 },
                BottomRight = new Point { X = 200, Y = 200 }
            };
            myRect.DisplayStats();

            Console.ReadLine();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Object Init Syntax *****\n");

            //  Make a Point by setting each property manually.
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            //  Or make a Point via a custom constructor.
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();

            //  Or make a Point using object init syntax.
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();

            //  Calling a custom contructor.
            //  Results on X = 100 and Y = 100.
            //  Not exactly usefull.
            Point pt = new Point(10, 16)
            {
                X = 100, Y = 100
            };

            pt.DisplayStats();

            //  Calling a more interesting custom constructor with init syntax.
            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90, Y = 20
            };

            goldPoint.DisplayStats();

            //  Create and initialize a Rectangle/
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Object Init Syntax *****\n");

            // manually setting properties
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            // using custom ctor
            Point anotherPoint = new Point();

            anotherPoint.DisplayStats();

            // init syntax
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();
            Console.ReadLine();

            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90, Y = 20
            };

            goldPoint.DisplayStats();
            Console.ReadLine();

            // Rectangle part
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();
            Console.ReadLine();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Create a point by setting each property manually:");
            Point p = new Point();

            p.X = 1;
            p.Y = 2;
            p.DisplayStats();

            Console.WriteLine("Create a point via the Custom Constructor:");
            Point q = new Point();

            q.DisplayStats();

            Console.WriteLine("Create a point using the object init syntax:");
            Point r = new Point {
                X = 30, Y = 30
            };                                      // Implicitly calling Default Constructor then setting Properties

            r.DisplayStats();

            Console.WriteLine("Now change the point Color using a Custom Constructor plus Specified Properties (default is BloodRed):");
            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90, Y = 20
            };

            goldPoint.DisplayStats();

            Console.WriteLine("Create a new Rectangle variable and set the inner Points");
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();

            Console.WriteLine();
            Console.ReadLine();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.WriteLine("**** Fun with object init syntax ****");
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 12;
            firstPoint.DisplayStats();
            Console.WriteLine();

            Point anotherPoint = new Point(32, 3);

            anotherPoint.DisplayStats();
            Console.WriteLine();

            Point finalPoint = new Point {
                X = 2, Y = 5
            };

            finalPoint.DisplayStats();
            Console.WriteLine();

            Point coloredPoint = new Point(PointColor.LightBlue)
            {
                X = 90, Y = 20
            };

            coloredPoint.DisplayStats();
            Console.WriteLine();

            Rectangle rect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            rect.DisplayStats();
            Console.WriteLine();

            Console.ReadLine();
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Fun with Object Init Syntax *****\n");

            // Make a Point by setting each property manually.
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            // Or make a Point via a custom constructor.
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();

            // Or make some Point types using the new object init syntax.
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();

            // Create and initialize a Rectangle.
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();

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

            // Make a Point by setting each property manually.
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();
            Console.WriteLine();

            // Or make a Point via a custom constructor.
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();
            Console.WriteLine();

            // Or make a Point using object init syntax.
            Point finalPoint = new Point
            {
                X = 30,
                Y = 30
            };

            finalPoint.DisplayStats();
            Console.WriteLine();

            // Calling a more interesting custom constructor with init syntax.
            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90,
                Y = 20
            };

            goldPoint.DisplayStats();
            Console.WriteLine();

            // Create and initialize a Rectangle.
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 15, Y = 15
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();

            Console.WriteLine();

            // another way of using Rectangle
            // since Rectangle creates TopLeft and BottomRight Points, just set them.

            Rectangle anotherRectangle = new Rectangle
            {
                TopLeft     = firstPoint,
                BottomRight = anotherPoint
            };

            anotherRectangle.DisplayStats();

            Console.WriteLine();

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

            // Make a Point by setting each property manually.
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;
            firstPoint.DisplayStats();

            // Or make a Point via a custom constructor.
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();

            // Or make a Point using object init syntax.
            // Here, the default constructor is called implicitly.
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();

            // Here, the default constructor is called explicitly.
            Point pt = new Point()
            {
                X = 30, Y = 30
            };

            pt.DisplayStats();

            // Calling a custom constructor.
            Point pt2 = new Point(10, 16)
            {
                X = 100, Y = 100
            };

            pt2.DisplayStats();

            // Calling a more interesting custom constructor with init syntax.
            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90, Y = 20
            };

            goldPoint.DisplayStats();

            // Create and initialize a Rectangle.
            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 10
                },
                BottomRight = new Point {
                    X = 200, Y = 200
                }
            };

            myRect.DisplayStats();

            // Old-school approach.
            Rectangle r  = new Rectangle();
            Point     p1 = new Point();

            p1.X      = 10;
            p1.Y      = 10;
            r.TopLeft = p1;
            Point p2 = new Point();

            p2.X          = 200;
            p2.Y          = 200;
            r.BottomRight = p2;
            r.DisplayStats();

            Console.ReadLine();
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            Console.WriteLine("OBJECT INIT SYTNAX");

            // Make a Point by setting each property manuall
            Point firstPoint = new Point();

            firstPoint.X = 10;
            firstPoint.Y = 10;

            firstPoint.DisplayStats();

            // Or make a Point via a Constructor
            Point anotherPoint = new Point(20, 20);

            anotherPoint.DisplayStats();

            // Or make a point using Init Syntax
            Point finalPoint = new Point {
                X = 30, Y = 30
            };

            finalPoint.DisplayStats();

            // The default constructor is called implicitly
            Point combinePoint = new Point {
                X = finalPoint.X, Y = firstPoint.Y
            };

            combinePoint.DisplayStats();

            // The defualt constructor is called explicitly

            Point exPoint = new Point()
            {
                X = firstPoint.Y, Y = anotherPoint.X
            };

            exPoint.DisplayStats();


            // Calling more interesting constructor with color
            Point goldPoint = new Point(PointColor.Gold)
            {
                X = 90, Y = 70
            };

            goldPoint.DisplayStats();

            // Using Object initialization syntax
            // creating new Rectangle Variable and set the inner Points

            Rectangle myRect = new Rectangle
            {
                TopLeft = new Point {
                    X = 10, Y = 50
                },
                BottomRight = new Point {
                    X = 20, Y = 30
                }
            };

            myRect.DisplayStats();
        }