What is the difference between these two variations of collection initialiser expressions? : <p>I've been using C# for a while, but recently noticed that the behaviour of one of my unit tests changed depending on which variation of collection initialiser expression I used:</p>

<ul>
<li><code>var object = new Class { SomeCollection = new List&lt;int&gt; { 1, 2, 3 } };</code></li>
<li><code>var object = new Class { SomeCollection = { 1, 2, 3 } };</code></li>
</ul>

<p>Up until this point I assumed that the second form was just syntactic sugar and was semantically equivalent to the first form. However, switching between these two forms resulted in my failing unit test passing.</p>

<p>The example code below demonstrates this:</p>

<pre class="lang-cs prettyprint-override"><code>void Main()
{
    var foo1 = new Foo { Items = new List&lt;int&gt; { 1, 2, 3} };
    var foo2 = new Foo { Items = { 1, 2, 3 } };

    foo1.Dump();
    foo2.Dump();
}

class Foo
{
    public List&lt;int&gt; Items { get; set; }
}
</code></pre>

<p>When I run this, the first assignment works fine but the second results in a <code>NullReferenceException</code>.</p>

<p>My gut feeling is that behind the scenes the compiler is treating these two expressions as this:</p>

<pre class="lang-cs prettyprint-override"><code>var foo1 = new Foo();
foo1.Items = new List&lt;int&gt; { 1, 2, 3 }; 

var foo2 = new Foo();
foo2.Items.Add(1);
foo2.Items.Add(2);
foo2.Items.Add(3);
</code></pre>

<p>Is that assumption accurate?</p>
