C# Stupidity
Consider the following code:
public interface IDemo
{
void DemoMethod();
}
public abstract class DemoBase : IDemo
{
public void DemoMethod(){ System.Console.WriteLine("from demo base"); }
}
public class Demo : DemoBase
{
public void DemoMethod() { System.Console.WriteLine("from demo");}
}
public class Other
{
public static void Main(string[] args)
{
IDemo idemo = new Demo();
idemo.DemoMethod();
}
}
What do you think will happen when you run this code?
'Demo.DemoMethod()' because it hides inherited member
'DemoBase.DemoMethod()'
test.cs(7,15): (Location of symbol related to previous warning)
from demo base
That wasn't what I meant, but I did get a warning, so let's add an override to Demo to make it work.
test.cs(11,23): error CS0506: 'Demo.DemoMethod()' : cannot override inherited
member 'DemoBase.DemoMethod()' because it is not marked virtual,
abstract, or override
test.cs(7,15): (Location of symbol related to previous error)
I've not dugged deep enough into the CLR to see how interface members are implemented, but it seems to me that an interface member is already virtual, why do I need to declare it twice? It's different than the way it's done with abstract classes. And I can't see a reason why.
Comments
Comment preview