12

转到实现细节,我看到Array类的实现为

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

IList 接口的实现读作

public interface IList : ICollection, IEnumerable

我的问题是,该类不是Array自动实现的吗?它实现ICollectionIEnumerable那一刻IList?为什么要明确实施这些?

4

2 回答 2

3

数组的实现是:

Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable

在此处查看此来源

也许你看了一下 MSDN,它只是让文档更清晰。

于 2013-02-19T10:52:36.967 回答
1
interface I
{
    void M();
}

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

    }
}

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

    }
}

您可以自由编写I i = new B(),但不能MB. 为此,您需要明确B实施I

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

    }
}
于 2013-02-19T10:54:43.170 回答