I need to change a method that has one parameter that takes a serie of objects. I need to find the lowest Interface (in inheritance tree) that has the Count property. Until now I was using the IEnumerable but as this has not Count I need to change it to the wider interface possible so the method can work with the biggest number of types of series (collections, lists, arrays, etc).
Thanks in advance.
ICollectionadds theCountproperty.As @Joren rightly points point,
IEnumerable<T>has the extension methodCount<T>()if you’re happy making your collection generic. However, as @Joel Coehoorn has pointed out, it is inadvisable to use this as it forces an iteration of the sequence.