'new'方法中的C#递归

use*_*747 3 c# new-operator

我的类 MyClass 中有此代码:

public new MyClass this[int index]
    {
        get
        {
            if (Count > index)
            {
                return this[index];
            }
            //...MyActions...
            return null;
        }
    }
Run Code Online (Sandbox Code Playgroud)

在字符串...

return this[index]
Run Code Online (Sandbox Code Playgroud)

...我有递归,但我需要在类中使用属性。我不知道怎么做。

例子:

 return base.this[index]
Run Code Online (Sandbox Code Playgroud)

但我不能“覆盖”这个方法,只能设置“新”。我难过

怎么办?对不起,我的英语很差,谢谢

Ily*_*nov 5

您可以使用base关键字来访问基类的成员,包括索引器。尝试使用下一个代码片段在基类上调用索引器:

return base[index];
Run Code Online (Sandbox Code Playgroud)