Possible Duplicate:
Why does one often see “null != variable” instead of “variable != null” in C#?
I see it from times to times and I'd like to know why. Is there any difference at all?
It's an old habit to avoid the accidental typo of myVar = null
(whoops). It's still helpful in some languages, but C# will protect you from doing it, so it's not necessary there.
It's a holdover from C where older compilers would not catch this:
if (foo = null)
when you mean this:
if (foo == null)
The classic joke example is this mistake:
if (fireTheNukes = true)
fireTheNukes();
This is generally accepted as an archaic pattern as any compiler worth its salt will catch an assignment within a conditional statement. I would avoid this pattern in your code as it serves no purpose these days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With