While reviewing some code I noticed the following code construct:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(product is null) | |
{ | |
} |
So far I’ve always written my null checks using the following syntax:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(product == null) | |
{ | |
} |
I wasn’t aware that this was even possible. Turns out this was introduced in C# 7.
Why would you use the ‘is’ keyword instead of ‘==’? The ‘is’ keyword ignores any operator overloads so you don’t end up with unexpected behavior when you are using operator overloading.
Learned something today? Check!