Different types of Object Initializers

Consider the bellow Point class

 class Point
    {
        int x, y;
        public int X
        {
            get { return x; }
            set { x = value; }
        }
        public int Y
        {
            get { return y; }
            set { y = value; }
        }
    }


Then consider the main Program

class Program
    {
        static void Main(string[] args)
        {
            Point c1=new Point();
            c1.X=10;
            c1.Y=100;
            Console.WriteLine(c1.X);
            Console.WriteLine(c1.Y);

            Point c2=new Point {X=20,Y=200};    // See the new type of Initializing

            Console.WriteLine(c2.X);
            Console.WriteLine(c2.Y);

            var p = new Point { X = 30, Y = 300 };    // See the new type of Initializing using "var" keyword

            Console.WriteLine(p.X);
            Console.WriteLine(p.Y);

            Console.ReadLine();
        }
    }

With complex fields, such as a square or a rectangle whose corners are
located at the points p1 and p2, you can create the Rectangle class as
follows:

    public class Rectangle
    {
        Point p1; Point p2;
        public Point ULcorner { get { return p1; } set { p1 = value; } }
        public Point LRcorner { get { return p2; } set { p2 = value; } }      
    }
You can create and initialize the Rectangle object like this:

         var rectangle = new Rectangle
        {
            ULcorner = new Point { X = 0, Y = 0 },
            LRcorner = new Point { X = 10, Y = 20 }
        };

Note that the semicolon at the end of the object initializer block.

: