IntroductionC# 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.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: