c#-接口

    xiaoxiao2025-08-06  6

    由于c#没有多继承,所以用接口可以实现多继承

    interface IWoman { void GetSon(); } interface IMan { void Publish(); } class Program : IMan,IWoman { static void Main(string[] args) { Program p = new Program(); p.Publish(); p.GetSon(); Console.ReadKey(); } public void Publish() { Console.WriteLine("IMan接口 Publish"); } public void GetSon() { Console.WriteLine("IWoMan接口 GetSon"); } }

    最新回复(0)