Last post Mar 16, 2018 06:32 AM by Pravin Damkondwar
Nov 27, 2006 08:11 PM|sun21170|LINK
The most traditional way of checking if an object is null is : if ( object == null)
Can I also use : if ( object is null)? If yes, then which is more efficient OR is there another better way of doing this?
Nov 27, 2006 08:30 PM|pkellner|LINK
Nov 27, 2006 09:08 PM|sun21170|LINK
But the String.IsNullOrEmpty is only for 'string'.
I was asking a question about an object, which could be of any type.
For example, if 'employee' was of type 'Employee', then could I use if (employee is null) or if (employee == null) and which one would be the best from performance point of view?
Nov 28, 2006 09:37 AM|JeffreyABecker|LINK
Nov 28, 2006 10:36 AM|David Anton|LINK
You must use "if (object == null)".
"object is null" won't even compile. The C# "is" operator is strictly for type checking, not identity comparisons.
Mar 16, 2018 06:32 AM|Pravin Damkondwar|LINK
if (object == null)
will give an error in SonarQube code quality review like
Change this condition so that it does not always evaluate to 'false'; some subsequent code is never executed.