Are there significant performance differences (at runtime and/or compile time) between constructing and assigning the properties of a class like this:
Employee currentUser = new Employee();
currentUser.Name = "Bob";
or like this:
Employee currentUser = new Employee() { Name = "Bob" };
My actual example is not that simple, the properties of the class are actually assigned to some long linq expressions.
I searched Google and Stack Overflow for answers but i only found questions regarding best practices, when to use either method, and not anything performance related.
Apologies in advance if i’m asking a silly question.
No. This is only a syntactic sugar. The IL generated will be the same (Will be updating with IL)
Now IL:
UPDATE
OK, after comments from Jon, it is obvious that there is a slight difference. But as for the question – mainly performance implications – there is none but as Jon points out, this can be important if an object is used for its own re-creation.