This project is read-only.

var album = new Album {Title= "Album"+ id }

Jan 18, 2013 at 6:12 PM

var album = new Album {Title= "Album"+ id } works 

instead of 

var album = new Album(Title="Album" +id) 

May I know how the constructor initializes the instance variable in the first case ?

Jan 21, 2013 at 9:02 PM
Edited Jan 21, 2013 at 9:03 PM

I try to explain in my own words: :(


It is like in creating an css file when you have to use the { } instead of ( ) because it won't be recognised or read.


I hope this is the answer you're looking for and hope that I understood you're question. :))

Jan 21, 2013 at 11:51 PM

This is taking advantage of C# Object Initializer syntax. From MSDN: "Object initializers let you assign values to any accessible fields or properties of an object at creation time without having to explicitly invoke a constructor."

More info here: