Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

An array of objects can be initialized in C# with the help of Object Initializer syntax, which allows you to initialize an array of objects using a concise syntax. For example:

MyClass[] myArray = new MyClass[] {
    new MyClass {Property1 = "Value1", Property2 = "Value2"},
    new MyClass {Property1 = "Value3", Property2 = "Value4"},
    new MyClass {Property1 = "Value5", Property2 = "Value6"}
};

In this example, a new array of MyClass objects is created, and each object is initialized with specific values using the object initializer syntax. This is a concise way of initializing an array of objects without having to implement a loop.