12

Going to the implementation details, I see the implementation of Array class as

public abstract class Array : ICloneable, IList, ICollection, IEnumerable, IStructuralComparable, IStructuralEquatable

Implementation of IList interface reads as

public interface IList : ICollection, IEnumerable

My question is, doesn't the Array class automatically implement ICollection and IEnumerable the moment it implements IList? Why are these implemented explicitly?

TheSilverBullet
  • 605
  • 7
  • 21
  • 2
    Though some of the methods of `ICollection`, `IList` and `IStructuralComparable` are implemented as explicit interface implementations, which is also documented on the MSDN page for the [`Array` class](http://msdn.microsoft.com/en-us/library/system.array.aspx). – Oded Feb 19 '13 at 10:47
  • 1
    @Oded, I checked this [link](http://msdn.microsoft.com/en-us/library/system.array.aspx) for the explicit interface implementations. I see explicit implementations for `ICollection` interface only. `IEnumerable` doesn't have any. – TheSilverBullet Feb 19 '13 at 11:35

2 Answers2

3

The implementation of Array is:

Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable

Take a look on this source in here

Maybe you took a look on MSDN which just make document clearer.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
cuongle
  • 74,024
  • 28
  • 151
  • 206
1
interface I
{
    void M();
}

class A : I
{
    void I.M()
    {

    }
}

class B : A
{
    void I.M() // Compilation error
    {

    }
}

You are free to write I i = new B(), but you can't implement explicitly M in B. In order to do that, you need B to implement I explicitly:

class B : A, I
{
    void I.M() // Is ok now.
    {

    }
}
Ryszard Dżegan
  • 24,366
  • 6
  • 38
  • 56