Code
using System;
using System.Collections.Generic;
using System.Text;
namespace InterfaceShadow
{
interface ISomeInterface
{
void DoSomething();
}
class Class1 : ISomeInterface
{
#region ISomeInterface 成员
public void DoSomething()
{
Console.WriteLine("Doing something in Class 1.");
}
#endregion
}
class Class2 : Class1, ISomeInterface
{
#region ISomeInterface 成员
void ISomeInterface.DoSomething()
{
Console.WriteLine("Explicitly doing something.");
}
public new void DoSomething()
{
Console.WriteLine("Doing something in Class 2.");
}
#endregion
}
class Program
{
static void Main(string[] args)
{
Class2 c2 = new Class2();
c2.DoSomething();
((ISomeInterface)c2).DoSomething();
((Class1)c2).DoSomething();
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace InterfaceShadow
{
interface ISomeInterface
{
void DoSomething();
}
class Class1 : ISomeInterface
{
#region ISomeInterface 成员
public void DoSomething()
{
Console.WriteLine("Doing something in Class 1.");
}
#endregion
}
class Class2 : Class1, ISomeInterface
{
#region ISomeInterface 成员
void ISomeInterface.DoSomething()
{
Console.WriteLine("Explicitly doing something.");
}
public new void DoSomething()
{
Console.WriteLine("Doing something in Class 2.");
}
#endregion
}
class Program
{
static void Main(string[] args)
{
Class2 c2 = new Class2();
c2.DoSomething();
((ISomeInterface)c2).DoSomething();
((Class1)c2).DoSomething();
Console.ReadLine();
}
}
}