4 ms·
Completely agree. C# has this right. An expression must produce a valid boolean value, the language does not evaluate any random type as boolean based on a set
by solutionyogi 13y ago
Completely agree. C# has this right. An expression must produce a valid boolean value, the language does not evaluate any random type as boolean based on a set of rules.
E.g. you can't say following in C#
if(number) //number is of type integer.
if(o1) //o1 is a reference type variable.
if("string")
if(number = 10) // number = 10 is an assignment and produces 10.
You must write:
if(number == 0)
if(o1 != null)
if("string".Length > 0)
if(number == 10)