how to get the default value of a type if the type is only known as System.Type?

Posted by Patrick Klug on Stack Overflow See other posts from Stack Overflow or by Patrick Klug
Published on 2009-08-15T04:37:17Z Indexed on 2010/05/12 2:44 UTC
Read the original article Hit count: 266

Filed under:
|
|

If I want a method that returns the default value of a given type and the method is generic I can return a default value like so:

public static T GetDefaultValue()
{
  return default(T);
}

Can I do something similar in case I have the type only as a System.Type object?

public static object GetDefaultValue(Type type)
{
  //???
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about generics