G
Guest
Something has changed from C# 1.0 to 2.0 regarding interface
re-implementation. See my sample code below; when compiled and run under VS
2003, you get:
Control.Paint
Control.IControl.Paint
But when compiled and run under VS 2005: you get:
Control.Paint
Control.Paint
Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an explicit
implementation of the base class.
Thanks
----
using System;
namespace InterfaceMapTest
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();
IControl iControl = obj as IControl;
iControl.Paint();
}
}
public interface IControl
{
void Paint();
}
class Control : IControl
{
public virtual void Paint()
{
Console.WriteLine("Control.Paint");
}
void IControl.Paint()
{
Console.WriteLine("Control.IControl.Paint");
}
}
class MyControl : Control, IControl
{
}
}
re-implementation. See my sample code below; when compiled and run under VS
2003, you get:
Control.Paint
Control.IControl.Paint
But when compiled and run under VS 2005: you get:
Control.Paint
Control.Paint
Please explain why in C# 2.0, a class that re-implements an interface
prefers to map to a virtual method of the base class rather than an explicit
implementation of the base class.
Thanks
----
using System;
namespace InterfaceMapTest
{
class MyApp
{
static void Main(string[] args)
{
MyControl obj = new MyControl();
obj.Paint();
IControl iControl = obj as IControl;
iControl.Paint();
}
}
public interface IControl
{
void Paint();
}
class Control : IControl
{
public virtual void Paint()
{
Console.WriteLine("Control.Paint");
}
void IControl.Paint()
{
Console.WriteLine("Control.IControl.Paint");
}
}
class MyControl : Control, IControl
{
}
}