Guillaume Paris
Guillaume Paris

Reputation: 10539

List<T> derived from IList<T> and from IEnumerable<T>, useless?

From mscorlib.dll:

public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{..}

public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>
{...}

Why List<T> have to explicitly derived from ICollection<T>, IEnumerable<T>, IEnumerable, in addition of derived from IList<T> which itself derived from ICollection<T>, IEnumerable<T>, IEnumerable ?

Upvotes: 2

Views: 131

Answers (2)

InBetween
InBetween

Reputation: 32760

The object browser or Reflector or similar don't have the source code, they have metadata to work with. Its not easy to know inspecting that information if a type implements directly an interface or not, so the easy option, because the ultimate goal is documentation, is to simply show all interfaces even if some are redundant.

For more information, read this.

Upvotes: 3

user743382
user743382

Reputation:

Don't trust decompiled code to be an accurate representation of the original source code.

The original source code contains only

public class List<T> : IList<T>, System.Collections.IList, IReadOnlyList<T>

So yes, you're right that List<T> doesn't need to be explicitly derived from ICollection<T> and others. It isn't.

Upvotes: 5

Related Questions