title: Are Structs always stack allocated or sometimes heap allocated?
body: <p>I was of the impression that in C#, struct elements are allocated on the stack and thus disappear when returning from a method in which they were created. But what happens if I place the struct-values in a list and return that? The elements survives. <strong>Are struct instances sometimes allocated on the heap?</strong></p>
  
  <pre><code>internal struct Stru
  {
    public int i;
  }
  
  internal class StruTry
  {
    public List&lt;Stru&gt; Get(int max)
    {
      var l = new List&lt;Stru&gt;();
      for (int i = 0; i &lt; max; i++)
        l.Add(new Stru {i=i});
  
      return l;
    }
  }
  </code></pre>
  
  <p>code printing 0, 1, 2</p>
  
  <pre><code>[Test]
  public void T()
  {
    var ll = new StruTry().Get(3);
    foreach (var stru in ll)
      Console.WriteLine("* "+ stru.i);
  }
  </code></pre>