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

mag*_*uri 2 c# collections inheritance this base-class

所以我上课了:

    class TestCollection : Collection<Person> {

    }
Run Code Online (Sandbox Code Playgroud)

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

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

        }
    }
Run Code Online (Sandbox Code Playgroud)

Mar*_*ell 5

当你继承某些东西时,原件不是"内部" - 它是同一个对象.所以答案最终是:this.如果你需要绕过virtual你已经覆盖的方法,那么:base.

Collection<T> 具体情况下,还有一个protected IList<T> Items {get;}属性可以从继承类型访问 - 因此您可以通过交谈来绕过一系列抽象Items而不是this.