我的屏幕底部有一个警告:
警告1'WindowsFormsApplication2.EventControlDataSet.Events'隐藏继承的成员'System.ComponentModel.MarshalByValueComponent.Events'.如果要隐藏,请使用new关键字.C:\ Users\myComputer\Desktop\Event Control\WindowsFormsApplication2\EventControlDataSet.Designer.cs 112 32 eventControl
如果我双击它,它会出现:
public EventsDataTable Events {
get {
return this.tableEvents;
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我如何摆脱这个?
wda*_*avo 130
您的类具有基类,并且此基类还具有名为Events的属性(非虚拟或抽象),您的类将重写该属性.如果您打算覆盖它,请在public修饰符后添加"new"关键字.例如
public new EventsDataTable Events
{
..
}
Run Code Online (Sandbox Code Playgroud)
如果您不想覆盖它,请将您的属性名称更改为其他名称.
Agg*_*sor 13
@wdavo是对的.功能也是如此.
如果覆盖基本函数(如Update),那么在子类中,您需要:
new void Update()
{
//do stufff
}
Run Code Online (Sandbox Code Playgroud)
如果在函数decleration开始时没有new,您将获得警告标志.
在下面的代码中,Class A实现接口IShow并实现其method ShowData。Class B继承Class A。为了在中使用ShowData方法Class B,我们必须new在ShowData方法中使用关键字来隐藏基类Class A方法,并使用override关键字来扩展方法。
interface IShow
{
protected void ShowData();
}
class A : IShow
{
protected void ShowData()
{
Console.WriteLine("This is Class A");
}
}
class B : A
{
protected new void ShowData()
{
Console.WriteLine("This is Class B");
}
}
Run Code Online (Sandbox Code Playgroud)