title: Object & Collection Initializers and Accessors
body: <p>I'd like to start off with that I'm new to C# so accessors and Object Initializers are a completely new concept to me. That said, I think I have an okay handle on them except the following example is really confusing me:</p>
  
  <pre><code>using System;
  using System.Collections.ObjectModel;
  
  class How {
      public ObservableCollection&lt;int&gt; Coll {
          get { return coll_; }
          set {
              Console.WriteLine("Setter for Coll Called!");
              coll_.Clear();
              foreach (int i in value)
                  coll_.Add(i);
          }
      }
  
      public string Field {
          get { return field_; }
          set {
              Console.WriteLine("Setter for field called");
              field_ = value;
          }
      }
  
      // To confirm the internal coll_ is actually set
      public void Test() {
          foreach(int i in coll_)
              Console.Write(i + " ");
      }
  
      public How() {
          coll_ = new ObservableCollection&lt;int&gt;();
          field_ = "";
      }
  
      private ObservableCollection&lt;int&gt; coll_;
      private string field_;
  }
  
  public class Test {
      public static void Main() {
          var how = new How {
              Coll = { 1, 2, 3, 4, 5 },
              Field = "Test Field",
          };
  
          Console.Write("Coll: ");
          foreach (int i in how.Coll)
              Console.Write(i + " ");
          Console.WriteLine();
  
          Console.WriteLine("Field: " + how.Field);
  
  
          Console.Write("Internal coll_: ");
          how.Test();
          Console.WriteLine();
      }
  }
  </code></pre>
  
  <p>The output of the above code is (see live example <a href="http://ideone.com/rcYE1Y" rel="nofollow noreferrer">here</a>):</p>
  
  <pre><code>Setter for field called
  Coll: 1 2 3 4 5 
  Field: Test Field
  Internal coll_: 1 2 3 4 5 
  </code></pre>
  
  <p><code>Field</code> operates exactly as I'd expect it to, but <code>Coll</code> confuses me. The setter to <code>Coll</code> is never called, which to me implies that Collection Initializers don't mix will with Properties (or at least non Auto-Properties). However, if that's the case, I would have expected a compile-time error.</p>
  
  <p>Regardless of that part of the behavior, what confuses me even further is that the internal value of <code>coll_</code> is somehow set to the initializer value.</p>
  
  <p>I'm interested in knowing a) why <code>Coll</code>'s set is not called, and also how C# is able to set the value of <code>coll_</code>. Is the use of that identifier in the get and set accessors for <code>Coll</code> enough for C# to identify <code>coll_</code> as the internal storage; or maybe since it's set because it's the only member of the corresponding type? </p>