Given an instance of an unknown reference or value type, is there any way to test whether the instance contains the default value for that type? I envisage something like this ...
bool IsDefaultValue(object value)
{
return value == default(value.GetType());
}
Of course, this doesn't work because GetType returns a runtime type, but I hope that somebody can suggest a similar technique. Thanks.
static bool IsDefaultValue<T>(T input)
{
return Object.Equals(input, default(T));
}
Note: you can't use ==
for equality using generic type T.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With