Nullable ToString()
- by StupidDeveloper
I see everywhere constructions like:
int? myVar = null;
string test = myVar.HasValue ? myVar.Value.ToString() : string.Empty;
Why not use simply:
string test = myVar.ToString();
Isn't that exactly the same ?
At least Reflector says that:
public override string ToString()
{
if (!this.HasValue)
{
return "";
}
return this.value.ToString();
}
So, is that correct (the shorter version) or am I missing something?