0

I found myself digging into System.Collections.Generic when using a BindingList. I don't understand something about the following interface implementations:

public interface ICollection<T> : IEnumerable<T>, IEnumerable
public interface ISet<T> : ICollection<T>, IEnumerable<T>, IEnumerable

Why does

ISet<T> 

Implement

IEnumerable<T>, IEnumerable 

when ICollection already does? Wouldn't the following be acceptable?

public interface ICollection<T> : IEnumerable<T>, IEnumerable
public interface ISet<T> : ICollection<T>

Any help understanding this is much appreciated. Thanks!

4
  • What source are you looking at? referencesource.microsoft.com/#System/compmod/system/… Commented May 1, 2018 at 13:37
  • Look at the source code: referencesource.microsoft.com/#System/compmod/system/… - It's just Visual Studio that's showing you all interfaces in the hierarchy Commented May 1, 2018 at 13:38
  • Microsoft likes repeating inherited interface declarations, it is excellent self-documentation. It makes no difference whatsoever to the code or the runtime behavior. Commented May 1, 2018 at 13:42
  • Thanks @HansPassant, your comment was the nice, concise answer I was really looking for. Commented May 1, 2018 at 14:36

1 Answer 1

2

I assume you have the interface declarations from MSDN or another documentation source. While it is right that ISet<T> does not have to explicitly implement IEnumerable<T> and IEnumerable as you can see in the reference implementation ...

public interface ISet<T> : ICollection<T> 

... documentations still contain the complete list as a convenience for the developer so they know what interfaces are implemented by ISet<T> even if only through inheritance. Going through a possibly long inheritance hierarchy would probably not enhance the benefit of such a documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

I figured this was a convenience/readability feature but thought I'd ask the community. Thanks @Adrian!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.