C# 6 allows declaration of parameterless constructors on structs. However they must be public and there are situations where one would like to force other developers to use parametrized constructor, so I'm wondering would it be ok from CLR perspective to make parameterless constructor unusable by throwing an exception inside, so it would look like that:
public struct Foo
{
public Foo()
{
throw new InvalidOperationException("This constructor is not supported.");
}
public Foo(int i) { ... }
}
new Foo[1];What constructor will be run to set the "default state"?Foo[] array = new Foo[5];and see what happens.default(Foo)instead to avoid calling a constructor.