接口与实现

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();
        }
    }
}

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

posted @ 2017-04-25 18:22  TBHacker  阅读(305)  评论(0编辑  收藏  举报