Object Initialization


Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor.

Object Initializers allows you to create an object directly and set its properties using just one statement.

Object Initializers ease construction and initialization of objects.

Object Initializers are especially useful in LINQ query expressions.

Code Example

Point p = new Point {X = 0, Y = 1};
List<int> digits = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };