【发布时间】:2009-07-20 05:41:11
【问题描述】:
我收到以下编译器警告:
'Resources.Foo.GetType()' hides inherited member 'object.GetType()'. Use the new keyword if hiding was intended. Resources.NET\Resources\Class1.cs 123 20 Resources
对于这个(非常简化的)代码:
public interface IFoo
{
int GetType();
string GetDisplayName();
}
public class Foo : IFoo
{
public int GetType() { return 3; } *** Warning: points to here (line 123)***
public string GetDisplayName() { return "Foo"; }
}
注意,我不明白为什么 GetDisplayName() 函数没有收到警告。我显然忽略了一些东西。
我在 Stack Overflow 上搜索了一下,并用谷歌搜索了这个错误,它似乎适用于类继承,而不是接口。我真的很困惑为什么会为接口触发(将其方法定义为虚拟)。
提前感谢您的洞察力。
【问题讨论】:
-
哇,你们都太不可思议了。 4 分钟内获得 4 个高质量答案!如何选择最佳答案?我认为链接为我做了它,虽然它很接近。再次感谢大家!
标签: c# inheritance interface method-hiding