I have a method with an object parameter.
public bool ContainsValue(object value)
I found that converting the object to an IList
works.
IList<object> list = (IList<object>)value;
However, converting it to a List
does not.
List<object> Ilist = (List<object>)value;
I looked at the definition of both the IList
and the List
and they both seem to implement the Enumerator
and Collection
interfaces. I am wondering why List
doesn't work but IList
does. Where in the framework does it crash and why?
If an object implements the IList interface, it doesn't mean that it is actually of the type List. It can be any other type implementing the IList interface.