Checking for null – what order? [duplicate]

The second version ( null == str ) is called a yoda condition.

They both result in the same behavior, but the second one has one advantage: It prevents you from accidentally changing a variable, when you forget one =. In that case the compiler returns an error at that row and you’re not left with some weird behavior of your code and the resulting debugging.

Leave a Comment