Alex Rivera | Logout

How can I check if a generic method parameter is a value type?

Asked 2011-10-03T13:27:31.363
9

Is there a way to check if a variable is value type of reference type?

Imagine:

private object GetSomething<T>(params T[] values) 
{
    foreach (var value in values)
    {
        bool is ValueType; // Check if 'value' is a value type or reference type
    }
}
Edit
Report

1 Answer

0

Your condition will look like

var cond = false;
if(value != null) 
  cond = value.GetType().IsValueType
answered 2011-10-03T13:29:39.287

Your Answer