title: Object initializer for readonly properties in c#
body: <p>If you have the class:</p>
  
  <pre><code>class Foo {
        Bar Bar { get; } = new Bar();
  }
  
  class Bar {
        string Prop {get; set; }
  }
  </code></pre>
  
  <p>You can use a object initialise like:</p>
  
  <pre><code>var foo = new Foo { 
      Bar = { Prop = "Hello World!" }
  }
  </code></pre>
  
  <p>If you have a class</p>
  
  <pre><code>class Foo2 {
        ICollection&lt;Bar&gt; Bars { get; } = new List&lt;Bar&gt;();
  }
  </code></pre>
  
  <p>You can write </p>
  
  <pre><code>var foo = new Foo2 { 
      Bars = { 
          new Bar { Prop = "Hello" }, 
          new Bar { Prop = "World" }
      }
  }
  </code></pre>
  
  <p>but, I would like to write something like</p>
  
  <pre><code>var items = new [] {"Hello", "World"};
  var foo = new Foo2 { 
      Bars = { items.Select(s =&gt; new Bar { Prop = s }) }
  }
  </code></pre>
  
  <p>However, the code above does not compile with:</p>
  
  <blockquote>
    <p>cannot assigne IEnumerable to Bar</p>
  </blockquote>
  
  <p>I cannot write:</p>
  
  <pre><code>var foo = new Foo2 { 
      Bars = items.Select(s =&gt; new Bar { Prop = s })
  }
  </code></pre>
  
  <p>Property Bars is readonly.</p>
  
  <p>Can this be archived?</p>