At clients, I see quite a few people being confused by this compiler error message:
Error 1 The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable'
One of the reasons about the confusion is that a string variable behaves like a value type, but in fact is a reference type because their values can consume a huge amount of memory (thanks User codekaizen).
A few interesting questions on that on StackOverflow:
- c# – Why strings behave like ValueType – Stack Overflow.
- c# – Why String behaves like value type while using == – Stack Overflow.
- In C#, why is String a reference type that behaves like a value type? – Stack Overflow.
- why string behaves as value type even though it is a reference type in c# – Stack Overflow.
- c# – Why .NET String is immutable? – Stack Overflow.
- .net – Is string a value type or a reference type? – Stack Overflow.
Anyway, back to the error message above.
Lots of people are confused by it, just see a few questions on StackOverflow: Read the rest of this entry »