c# - Is there any subtle difference between inline initializing a list with or without '()'? -


e.g. there technical difference between invoking:

list<string> list = new list<t> () { "one", "two", "tree" };  // () 

and

list<string> list = new list<t> { "one", "two", "tree" };    // without () 

?

the result same. interested if there technical difference in way of invocation or convenience .net c# shortcut.

there no difference. parenthesis not required when using collection initializer default constructor. however, if want use constructor cannot omit parenthesis.

some code refactoring tools resharper indicate showing parenthesis redundant.

collection initializers not limited "built-in" .net types. type implementing ienumerable , providing suitable add method can use collection initializer.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -