【Interface Property】
interface (C# Reference).
按如下形式实现interfac来避免冲突。
在没有interface前缀的情况下,编译器不会报错,2个interface引用同一方法:
class Test { static void Main() { SampleClass sc = new SampleClass(); IControl ctrl = (IControl)sc; ISurface srfc = (ISurface)sc; // The following lines all call the same method. sc.Paint(); ctrl.Paint(); srfc.Paint(); } } interface IControl { void Paint(); } interface ISurface { void Paint(); } class SampleClass : IControl, ISurface { // Both ISurface.Paint and IControl.Paint call this method. public void Paint() { Console.WriteLine("Paint method in SampleClass"); } } // Output: // Paint method in SampleClass // Paint method in SampleClass // Paint method in SampleClass