lance lance - 3 months ago 10
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)) { ... }


and

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


How do these two perform differently?

Answer

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

MSDN's C# reference page for default keyword: https://msdn.microsoft.com/en-us/library/25tdedf5.aspx.