于梦想齐行
于梦想齐行

C#接口

C#接口
using System;

namespace ConsoleApp1
{
    interface IMyInterface
    {
        void MethodToImplement();
    }
    class InterfaceImpl: IMyInterface
    {
        public void MethodToImplement()
        {
            Console.WriteLine("MethodToImplement() called.");
        }
    }
    interface IParentInterface2
    {
        void ParentInterfaceMethod();
    }
    interface IMyInterface2: IParentInterface2
    {
        void MethodToImpl();
    }
    class InterfaceImpl2 : IMyInterface2
    {
        public void ParentInterfaceMethod()
        {
            Console.WriteLine("ParentInterfaceMethod() called.");
        }
        public void MethodToImpl()
        {
            Console.WriteLine("MethodToImpl() called.");
        }
    }
    class Program
    {
         static void Main(string[] args)
         {
            //接口
            InterfaceImpl i = new InterfaceImpl();
            i.MethodToImplement();

            InterfaceImpl2 i2 = new InterfaceImpl2();
            i2.MethodToImpl();
            i2.ParentInterfaceMethod();

            Console.ReadKey();
         }
    }
    
}
没有标签
首页      CSharp      C#接口

于梦想齐行

C#接口
using System; namespace ConsoleApp1 { interface IMyInterface { void MethodToImplement(); } class InterfaceImpl: IMyInterface { …
扫描二维码继续阅读
2022-06-25
近期文章
近期评论