How to implement some constrained .NET struct/structure (let's say LimitedString), where its state with default values (set by CLR to technical defaults, i.e. nulls, zeros, etc.) should be prohibited due to some design constraint?For example in case of trivial struct LimitedString, properties are String Value and int MaxLength = 10, where value of the MaxLength property must be at least 1. Value 0 is not allowed by design. But when I initalize the structure, I have 0 there. How to force value 10 into defaults?I see two options:Throw exception in static (vb.net shared) parameterless constructor  force using only costructor(s) with parameters. Impractical, parameterless use is expected sometimes.Add helper private field IsInitialized and while it is false, assume default values, i.e. MaxLength = 10. Slightly higher complexity inside the struct.Is option #2 a legitimate way or does this violate some design principles?Is there some better way than option #2?EDIT: option #1 won't work anyway, mentioned constructor is called every time, even if other constructors are called.
C#/VB struct  how to avoid case with zero default values, which is considered invalid for given structure?
c#;.net;data structures;vb.net;rules and constraints
Unless you have a really, really good reason that this has to remain a Struct, I would recommend that you convert it to a Class.That way, initialisation is completely under your control, through the Constructor(s) of that Class. If you really can't convert it, then I'd suggest creating a Factory Class to construct instances of this Struct; that class then takes on the responsibility for properly initialising instances of the Struct. 