Does maintenance become a nightmare on code that allows a nullable type of a value type? I realize that int? is the equivalent of Nullable<int>, but my question is more geared towards the usability of it. We see value types and naturally overlook them as not allowing null. But bringing in the Nullable<T> with a shorthand of the question mark, it’s obvious what it does but not always noticeable.
Is this one of those features that just because you can do it, doesn’t mean you should?
What should be the preference? A default value of a value type (i.e. int SomeConfigOption = -1;) or utilizing Nullable<T> (i.e. int? SomeConfigOption;)?
In this case clearly you want
Nullable<T>whenever you have the case that you have to account for the absence of a value. Magic numbers like -1 are a far worse maintenance nightmare.This is a core feature of the C# language, as with other features it can be abused but it provides clear benefits as well – these benefits far outweigh any problems someone not proficient in the language might have reading the source code – time to get up to speed.