I work with C# 8 with non nullable reference types and I define a class MyClass
:
class MyClass
{
public int Prop1 { get; set; } = 0;
public bool Prop2 { get; set; } = false;
}
I want to create an array
var myArray = new MyClass[10];
Since I am working with non nullable reference types and I am defining the default values for each property in my class, I'd expect that myArray
would be initialised with a this "default" object, with Prop1 = 0
and Prop2 = false
. However, even with non nullable types, the default value is still null.
Is there a way to define (override) the default value so that when I use the tag default
or when I create an array it uses this more consistent element?