C#: How to get the default value for a type using reflection
The following code snippet gives you the default value for the given type:
public static object GetDefaultValue(Type type)
{
object value = null;
if (type.IsValueType)
value = Activator.CreateInstance(type);
else
value = null;
return value;
}
Published: 19.08.2010
blog comments powered by Disqus

