Search code examples
c#coding-style

When to use !() or != when if not null


Whilst refactoring code I changed the all the if not null conditions to follow the majority convention in my code of

if (!(foo == null))

instead of

if (foo != null)

Is there any advantage in either statement?

Is there any advantage in either statement in c#?


Solution

  • I find the second one more readable.

    Apart from that, there is no difference.

    It is more important to pick a convention with your team and stick to it within any one particular codebase.