c# 4.0 - In C# bool? x = true; if (x == true) looks awkward -
bool? x = true; if (x == true)
looks awkward.
but needed.
is there better way?
edit:
thank attempts, far have not found way beat original. guess need deal awkwardness, perhaps comment it.
depending on situation, may want use null coalescing operator, lets specify default value you'll use if bool?
not set. it's not shorter conditional, think it's useful:
if(x ?? true) //defaults true if x not set
or, directly replicate case (and due popular demand):
if(x ?? false) //defaults false if x not set
Comments
Post a Comment