Possible Duplicate:
getting type T from IEnumerable<T>
I Have a property type of IEnumerable
public IEnumerable PossibleValues { get; set; }
How can I discover the base type that it was instanced?
For example, if it was created like this:
PossibleValues = new int?[] { 1, 2 }
I want to know that type is ‘int’.
You can do this if you want the type of PossibleValues:
Or you can do this if you want the type of an item contained in PossibleValues (assuming the array actually has values as described in your question):
EDIT
If it’s a possibility that the array may contain no items, then you’ll have to do some null checking, of course: