Object Initializers

Allows you to instantiate and initialize objects in one compound statement
Let you assign values to any accessible fields or properties at creation without having to explicitely invoke a constructor

MyClass instance = new MyClass { MyField=10, MyProperty="text" }; 

instead of

MyClass instance = new MyClass(); 
instance.MyField = 10;
instance.MyProperty = "text";

© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext