Is variable assignment expensive compared to a null check? For example, is it worth checking that foo is not null before assigning it null?
if (foo != null)
foo = null;
if (foo != null)
foo = null;
If I look at the second block code I would think that you only wanted to set the foo variable to null if it was not null before, and if I look at the first code I would think that you wanted to set the variable foo to null anyway.
I know this is because of the example you wrote, but in the end this kind of micro-optimization only adds confusion (it's not worth it).