Friday, 27 September 2013

Parenthesis with object initializers

Parenthesis with object initializers

In C#, I can have a class such as:
class MyClass {
public void DoStuff();
}
I can initialize this class like:
MyClass mc = new MyClass();
Or:
MyClass mc = new MyClass { };
If I don't need the parenthesis, and there are no properties to be set by
an object initializer, why can't I do this?
MyClass mc = new MyClass;

No comments:

Post a Comment