如何访问继承 Collection<> 的 class 中的集合?

How to access the collection inside a class which inherits Collection<>?

所以我有一个 class:

    class TestCollection : Collection<Person> {

    }

我从 main 添加了两个 Person 对象。我想知道有没有办法在不通过 TestCollection tc 的情况下访问 TestMethod 中的这两个对象?例如

    class TestCollection : Collection<Person> {
        public void TestMethod(TestCollection tc) {

        }
    }

当您继承某些东西时,原来的不是 "inside" - 它 是同一个对象 。所以最终答案是:this。如果您需要绕过已覆盖的 virtual 方法,则:base.

Collection<T> 特别是 的情况下,还有一个 protected IList<T> Items {get;} 属性 可以从继承类型访问 - 所以你可以通过与 Items 而不是 this.

交谈来绕过 范围 的抽象