title: C# Object initializer without default constructor
body: <p>I am trying to create an object using c# object initializer. But that class already has a constructor with one argument as per the need and I dont have a need for a default construcor so I didn't provide one. Compiler too won't provide a default constructor when there is a user-provided constructor in the class.</p>
  
  <p>Now the problem arises when I try to create an instance of this class using an object initializer:</p>
  
  <pre><code>public class Foo
  {
      public int Data { get; set; }
      public Foo(int Data)
      {
          this.Data = Data;
      }
  }
  </code></pre>
  
  <p>I instantiate the class like this:</p>
  
  <pre><code> Foo f=new Foo { Data=10};
  </code></pre>
  
  <p>And now I'm getting a compile-time error:</p>
  
  <p>"Foo does not contain a constructor that takes 0 argument"</p>
  
  <p>I know the error, it's because of the lack of a default constructor. When I don't have a need for the default constructor why should I provide one just for using object initializer? So I am just wondering, is there is any other way (style, syntactically) I can use this object initializer without explicitly providing a default constructor?</p>
  
  <p>I checked <a href="http://msdn.microsoft.com/en-us/library/vstudio/bb397680.aspx" rel="nofollow">this MSDN link</a>, it says if you have a PRIVATE default constructor in your class you can't use object initializer, but I dont have a private default constructor here. </p>