Object Initializer

An object initializer is used to initialize the object without making calls to it’s one of the constructors.

The reason for creating this is to avoid the creation of multiple constructors.
public class ObjectIntializer
public string Name;
public string Surname;

public ObjectIntializer()
    Console.WriteLine("I called");

var Obj = new ObjectIntializer
Name = “sagar”,
Surname = “Jaybhay”
This is object Initailizer syntax and when you create this the default or paramtrize constructor is called.

.NET Foundation Website | Blog | Projects | Code of Conduct