接口与实现

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{   

    public interface IMyInterface
    {
        void DoSomething();
        void DoSomethingElse();
    }

    public class MyClass : IMyInterface
    {
        public void DoSomething()
        {
            Console.WriteLine("DoSomething");
        }

        public void DoSomethingElse()
        {
            Console.WriteLine("DoSomethingElse");
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            MyClass myObject = new MyClass();
            myObject.DoSomething();
            myObject.DoSomethingElse();
            Console.ReadKey();
        }
    }
}

一个类,如果继承了某个接口。那么它必须把接口的方法都实现了,哪怕是一个空的。


本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6763641.html,如需转载请自行联系原作者

相关文章: