Introduction
C# 3.0 introduced another interesting feature Object and Collection initialization expressions.
If you take Employee Class as an Example:
We can use Object Initialization Expressions in C#3.0 Features to create an Employee as follows:
Now observe the above code we have neither invoked the constructor nor set the any properties directly. The code above is equivalent to the following code:
We can use Collection Initialization Expressions in C#3.0 Features to create a list of Employees as follows:
The advantage of using this feature is that it saves your time for creating a lot of constructors or initializing the individual property.
Object and Collection Initializers Feature in C# 3.0
Object Initialization Expressions allows you to initialize an object without invoking the constructor and setting its properties.


Jes HansenPosted Oct 20, 2008, 10:59 PM EDT
The ID is a private field and it has no public setter, thus you cannot use object initialization, or am I missing something?