title: Private-setter properties in C# 3.0 object initialization
body: <p>If I have the following code:</p>
  
  <pre><code>public class MyClass 
  { 
    public string myName { get; private set; } 
    public string myId { get; set; } 
  } 
  </code></pre>
  
  <p>A private compiler-generated variable is created for the setter. I want the setter not to be accessible for object initialization only.  But, how do I get to initially set the myName variable?</p>
  
  <p>Reading about object initialization I found the following:</p>
  
  <blockquote>
    <p>... it’s read-only  and the
    private field representing the
    underlying storage has a
    compiler-generated name that we 
    cannot use in a constructor to assign
    to it. The solution is to use [...] object
    initializers</p>
  </blockquote>
  
  <p>The solution would be, then, to use:</p>
  
  <pre><code>MyClass mc = new MyClass { 
  myName = "What ever", 
  myId = "1234" 
  };
  </code></pre>
  
  <p>But this ends up in a compiler error sayin that:</p>
  
  <blockquote>
    <p>The property or indexer
    'MyClass.MyClass.myName'
    cannot be used in this context because
    the set accessor is inaccessible</p>
  </blockquote>
  
  <p>So, is there a way to achieve setting this value using object initialization? If there is, what is the correct way to do it?</p>