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.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

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