Possible Duplicate:
C# – Programmatic equivalent of default(Type)
Is there a method or property in the Type class (or elsewhere) that I can use to find the value of default(T)?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just check
type.IsValueType; if that is true useActivator.CreateInstance(type)– otherwise it is null.It also helps that you can pass null to SetValue on a PropertyInfo or FieldInfo and it will work for value-types with even for int, float etc.