I was just dealing with strings, and I find myself annoyed that strings can be nullable. So, I have to have
if((teststring??string.Empty)==string.Empty)
all over the place. Would string? have been so hard for allowing nullability in the relatively few cases where it is needed (dbs, idiot user inputs, etc.). I also find myself irritated with having to export readonly interfaces in the cases where I want some form of const correctness. So, what C# language construct/decision annoys you?
EDIT: Thanks for the isnullorempty function, I hadn’t seen that before! Still doesn’t lessen my annoyance at it being nullable 😀
Making string a reference type seems entirely reasonable to me.
It’s a shame that one can’t declare a variable/parameter/return type to be non-nullable though – e.g.
Code contracts in .NET 4.0 will help with this, I believe – but it’s a bit late to make it pervasive.
A while ago I wrote a blog entry on the mistakes of C#. To summarise that post:
C# 1:
C# 2:
System.Nullableclass (notNullable<T>– that’s fine!)C# 3: