Object Initializers - To Parenthesize or Not To Parenthesize (that is the question)
What is the difference between the object initializers on lines 1 and 2? In what situations should one be preferred over the other?
8 Replies
There is no difference, the
()
can be omitted if you have an object initializerwhy does the second one exist
¯\_(ツ)_/¯
lmao
can you put parameters in it?
arguments
*
If there is a constructor that does require parameters, you can still call it (and have an initializer after it)
ah i see
so the second one is just there for consistency i guess
and the first is a shorthand
?
yeah I suppose
I'm also curious what the reasoning is for allowing
()
to be omittedi personally prefer it without the
()
so i guess it's just a pleasant shorthand
ajyway tnaks
thanks
:))