简体   繁体   中英

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 ?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM