Sorry if my question seem stupid.
In C++, this code work:
Foo* foo = new Foo();
if (foo)
....;
else
....;
In C#, this doesn't work:
Object obj = new Object();
if (obj)
....;
else
....;
because Object
class cannot be implicitly convert to bool
(obvious, no problem about that), and it doesn't implement true
operator.
So my question is why doesn't Object
implement the true
operator (just check whether itself is null or not, sound easy enough)? Is it just because of code readability or something?