I have a class similar to the following that uses an internal List:
public class MyList<T> : IEnumerable<T>
{
private List<T> _lstInternal;
public MyList()
{
_lstInternal = new List<T>();
}
public static implicit operator List<T>(MyList<T> toCast)
{
return toCast._lstInternal;
}
}
When I try to pass MyList<object>
to a function that takes a List<object>
, I get an InvalidCastException. Why?