ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsDefaultForType

Returns true or false depending on if the given object is equal to the default(T) value of the type.

Source

public static bool IsDefaultForType<T>(this T val)
{
    return EqualityComparer<T>.Default.Equals(val, default(T));
}

Example

var obj = SomeComplexFunction();

if(obj.IsDefaultForType())
{
    RunSomethingElse();
}

Author: Adam

Submitted on: 18 jul. 2013

Language: C#

Type: System.Object

Views: 4893