DEV Community

Discussion on: Existentially quantified types in C# - Part 2

Collapse
 
jwp profile image
John Peters

Polymorphic in that each item in list can be of any type right? Not polymorphic in that each list item can have multiple types or can it?

Collapse
 
shimmer profile image
Brian Berns • Edited

A list "carton" is a lot like an IList<T>. Each carton contains only one type of item. You can create a carton of ints or a carton of strings, and you can ensure that ints and strings aren’t mixed together in a single carton.

The important difference between an IList<T> and an IListCarton is that a carton of ints and a carton of strings have exactly the same type (IListCarton), but IList<int> isn't the same type as IList<string>.