显示实现接口和实现接口

显示实现接口的目的,是为了解决方法中方法重名的问题

显示实现接口是私有的,因此只能通过接口来访问。

View Code
 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             IFlyable fly = new Person();
 6             fly.Fly();
 7             ISuperable super = new Person();
 8             //只能通过接口调用
 9             super.Fly();
10             Person p = new Person();
11             //不能使用ISuperable的方法,因为是私有方法            
12             p.Fly();
13             Console.ReadKey();
14         }
15     }
16   public interface ISuperable
17     {
18         void Fly();
19     }
20    public interface IFlyable
21     {
22         void Fly();
23     }
24     public class Person : IFlyable, ISuperable
25     {
26 
27         public void Fly()
28         {
29             Console.WriteLine("普通实现");
30         }
31         void ISuperable.Fly()
32         {
33             Console.WriteLine("显示实现接口");
34         }
35     }
原文地址:https://www.cnblogs.com/cheshui/p/2701463.html