这是msdn中的一段话:
C# allows derived classes to contain methods with the same name as base class methods.- The base class method must be defined virtual.
- If the method in the derived class is not preceded by new or override keywords, the compiler will issue a warning and the method will behave as if the new keyword were present.
- If the method in the derived class is preceded with the new keyword, the method is defined as being independent of the method in the base class.
- If the method in the derived class is preceded with the override keyword, objects of the derived class will call that method rather than the base class method.
- The base class method can be called from within the derived class using the base keyword.
但是我发现第一句话不对啊:
class
CTime
{
public int GetTime()
{
return 1 ;
}
};
class CMinute : CTime
{
public new int GetTime()
{
return 0 ;
}
};
{
public int GetTime()
{
return 1 ;
}
};
class CMinute : CTime
{
public new int GetTime()
{
return 0 ;
}
};
这段代码运行的很好啊,但是base class的函数GetTime()不是virtual。
不知道改怎么理解