原文:http://msdn.microsoft.com/en-au/library/ms173157.aspx

 IControl
{
    void Paint();
}
interface ISurface
{
    
void Paint();
}
class SampleClass : IControl, ISurface
{
    
// Both ISurface.Paint and IControl.Paint call this method.
    public void Paint()
    {
    }
}

public class SampleClass : IControl, ISurface
{
    
void IControl.Paint()
    {
        System.Console.WriteLine(
"IControl.Paint");
    }
    
void ISurface.Paint()
    {
        System.Console.WriteLine(
"ISurface.Paint");
    }
}

//----------------

SampleClass obj 
= new SampleClass();
//obj.Paint();  // Compiler error.

IControl c 
= (IControl)obj;
c.Paint();  
// Calls IControl.Paint on SampleClass.

ISurface s 
= (ISurface)obj;
s.Paint(); 
// Calls ISurface.Paint on SampleClass.

///-----

interface ILeft
{
    
int P { get;}
}
interface IRight
{
    
int P();
}
class Middle : ILeft, IRight
{
    
public int P() { return 0; }
    
int ILeft.P { get { return 0; } }
}

相关文章: