lance lance - 1 year ago 90
C# Question

check against: null vs default()?

I want to check if a reference type is null. I see two options (_settings is of reference type FooType):

if (_settings == default(FooType)) { ... }


if (_settings == null) { ... }

How do these two perform differently?

Answer Source

There's no difference. The default value of any reference type is null.

MSDN's C# reference page for default keyword:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download