IsDefaultForType
public static bool IsDefaultForType<T>(this T val) { return EqualityComparer<T>.Default.Equals(val, default(T)); }Example:
var obj = SomeComplexFunction(); if(obj.IsDefaultForType()) { RunSomethingElse(); }
Description
Returns true or false depending on if the given object is equal to the default(T) value of the type.
Details
- Author: Adam
- Submitted on: 18-7-2013 20:23:41
- Language: C#
- Type: System.Object
- Views: 2435
Double click on the code to select all.