One of my (senior) employees is doing something really strange in his code.
Instead of checking the variable for null, it checks the type. And since
null is FooType
really returns false, this works.
public class Foo
{
private string _bar = null;
public string Bar
{
get
{
return (_bar is string) ? _bar : "";
}
set { _bar = value; }
}
}
I think this is bad coding, and it seems Resharper agrees with me. Is there a reason to write a check this way?
Is this a valid way to check for a variable? Or can it be considered bad style or maybe even harmful in some special cases?
I do not want to confront him, if I'm not sure that this really does not make sense.
source
share