Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have a question related to the Collection<t> class.

The collection class is:

C#
class Collection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable


Why does the Collection class implements ICollection and IEnumerable when it is already present in the IList. The Collection<t> class is implementing IList so it will implicitly have ICollection and IEnumerable.

C#
public interface IList : ICollection, IEnumerable
Posted

1 solution

Probably, just to remind you when you look at the documentation that IList does include ICollection and IEnumerable!

If you use the VS shortcut to implement the interface you will get the same function prototypes regardless, so it is likely just a documentation thing - there is no need in your class to do the same, unless you want the completeness in your documentation as well. A VS Explicit implementation includes the appropriate class prefix if you need it anyway.
 
Share this answer
 
Comments
Sakshi Smriti 22-Oct-13 4:47am    
So does it means that it(inheriting ICollection and IEnumerable in Collection<t> class) has been done by Microsoft just for completeness purpose
OriginalGriff 22-Oct-13 4:56am    
Completeness in the documentation, yes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900