'new'方法中的C#递归

标签 c# new-operator

我的类(class) MyClass 中有这段代码:

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

在字符串中...

return this[index]

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

例子:

 return base.this[index]

但我不能“覆盖”这个方法,只能设置"new"。我很伤心

怎么做? 对不起,我的英语很糟糕,谢谢

最佳答案

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

return base[index];

关于 'new'方法中的C#递归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14955939/

相关文章:

c# - Visual Studio 正则表达式替换重复捕获组

c# - 成员隐藏,其实际用途是什么

c++ - 我如何能够在 C++ 中声明一个在运行时确定的可变长度数组?

c# - 有什么方法可以创建一个可能具有不同调用和返回参数对象的方法吗?

c# - 隐藏三元运算符的扩展

c++ - 调用 free() 或 delete 而不是 delete[] 有什么危险吗?

c++ - 错误 C3662 : override specifier 'new' only allowed on member functions of managed classes

c++ - 使用新数组创建而不声明大小

c# - 无法绑定(bind)多部分标识符 "sxxx@yahoo.com"

c# - 在代码隐藏中将表添加到 FlowDocument