I have Type and I want to get the default value. For example, if Type is class or nullable I should get null. But if it is integer, DateTime. decimal, … I should get 0. What is the best way of doing this?
>Solution :
I expect you can use something like this:
public static object GetDefaultValue(Type type)
{
return type.IsClass ? null : Activator.CreateInstance(type);
}