I admit I'm far from experienced with c#, so this may be obvious, but I have to ask -- is there any difference between the two code samples? In case it's not obvious, the first statement omits () at the end of new operator. Is there any difference there or is () simply redundant in this context?
private static Dictionary<string, string> dict1 = new Dictionary<string, string>
{
{ "a", "A" },
{ "b", "B" }
};
private static Dictionary<string, string> dict2 = new Dictionary<string, string>()
{
{ "a", "A" },
{ "b", "B" }
};
Is there any difference there or is () simply redundant in this context?
There is no difference. Adding the ()
is optional when using a collection initializer, but the resulting compiled IL is identical.