Wednesday, April 6, 2011

Why does IEnumerable<T> derive from IEnumerable?

Duplicate:

Why IEnumerable<T> inherits from IEnumerable?


It looks like IEnumerable, ICollection, IList and their generic equivalents are in separate branches.

From stackoverflow
  • It does this so that all older methods and code that knows how to handle an IEnumerable is guaranteed to work with your collections.

    Implementing IEnumerable<T> implicitly means you implement IEnumerable.

    By branches, do you mean namespaces?

    Joan Venge : Thanks. By branches I meant, they are like List vs List, are independent of each other.
    Joan Venge : But couldn't they update those old methods to also work with the generic version?
    Michael Burr : This way old assemblies expecting IEnumerable will work with the IEnumerable class. Sometimes there isn't source code to modify (ie., the new class is part of something that plugs into an existing app at runtime, someone using a library that provides only assemblies, no source).
    Lasse V. Karlsen : Nor might it be worth the time to fix already working code like that.

0 comments:

Post a Comment