2

I just came across a scenario with a unit test where I am using CollectionAssert.AreEquivalent() with two instances of ICollection(T). However, CollectionAssert.AreEquivalent takes two ICollection objects as parameters and ICollection(T) does not implement ICollection. Why is that? I would think that since ICollection(T) is the generic equivalent to ICollection, it should implement ICollection for interoperability with older code; otherwise, if ICollection(T) is doing something fundamentally different than ICollection, it should not even be called ICollection(T).

millimoose
  • 39,073
  • 9
  • 82
  • 134
Bart Sipes
  • 921
  • 8
  • 21
  • @BartSipes Last but not least, it takes extra work for a generic collection *implementation* to implement a non-generic interface - you have to duplicate methods and have casts and generally make a non-typesafe mess of things. **Forcing** everyone who wants to implement their own custom collections to do that would be annoying, the .NET base library mostly does that for convenience in migrating old code. (This doesn't really apply to `ICollection` vs `ICollection`, but it does to `IList` and `IList`.) – millimoose Jun 04 '13 at 01:49

0 Answers0