For any reference type, the default value is a null instance. For any type of value, the default value can be obtained using Activator.CreateInstance
. But when you have a variable called instance
that assumes you need the actual instance, not a null reference ... Therefore, when you can do this:
public object GetDefaultValue(Type type) { return type.IsValueType ? Activator.CreateInstance(type) : null; }
... it's not entirely clear how useful this is. This is the default value for the type, which does not match the default instance for the type.
source share