In .NET, a value type (C# struct) can\'t have a constructor with no parameters. According to this post this is mandated by the CLI specification. What happens i
What I use is the null-coalescing operator (??) combined with a backing field like this:
public struct SomeStruct {
private SomeRefType m_MyRefVariableBackingField;
public SomeRefType MyRefVariable {
get { return m_MyRefVariableBackingField ?? (m_MyRefVariableBackingField = new SomeRefType()); }
}
}
Hope this helps ;)
Note: the null coalescing assignment is currently a feature proposal for C# 8.0.