3 ms·
Type parameters are invariant, unless explicitly specified to be covariant with a where clause.
by pcwalton 14y ago
Type parameters are invariant, unless explicitly specified to be covariant with a where clause.
- Peaker 14y agoWell, if List<T> is invariant on the T, then you cannot usefully have lists parameterized on interfaces, which is losing a useful ability. I'd say that classifies as a thorny edge case. In Haskell, I can represent the type: (Show a, Ord a) => [a] It seems like the same is impossible in C# due to generics' interaction with inheritance.