gpt4 book ai didi

'new'方法中的C#递归

转载 作者:行者123 更新时间:2023-12-04 23:03:11 27 4
gpt4 key购买 nike

我的类(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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com