As in the title, does anyone know why the ICollection interface does not contain the Add method? It seems very strange that the general version of ICollection<T> has Add , but ICollection does not. Anyone with a deeper knowledge of this will be really helpful.
As for me, unfortunately, the developers who build SharePoint have never learned about generics, so each individual collection in the API is not a shared collection based on ICollection . I would like to add several extension methods to ICollection , which include, but are not limited to, adding to the collection, but this seems impossible (at least impossible without reflection).
EDIT:
Quite a lot of people talk about the reason, because ICollection.Add will require an Object and, therefore, will not be typeafe. This is not true. IList has an Add method that takes an Object . You just need to do typecheck and cast in the method that takes Object .
The argument that the array implements ICollection , and therefore it cannot have Add , also does not contain water. If ICollection had an Add method, it just needs to be explicitly implemented on arrays and throw an exception (like many arrays of arrays currently existing).
I really hoped that someone had a link to an explanation from one of the designers.
MgSam
source share