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.
ICollection
adds the Count
property.
As @Joren rightly points point, IEnumerable<T>
has the extension method Count<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.
ICollection adds the Count property.
System.Collections.ICollection
, and also System.Collections.Generic.ICollection<T>
. These two interfaces have no relation to eachother, but both inherit from IEnumerable, so they're at the same level.
IEnumerable obviously does not have a Count property (the count isn't necessarily predetermined).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With