lance lance - 6 months ago 41
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?


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

MSDN's C# reference page for default keyword: