c# interface介面

wisdomone1發表於2012-03-11

using System;
using System.Collections.Generic;
using System.Text;

namespace learninterface1
{
    //類繼承多個介面,繼承介面可能是父子介面關係
    //類必須實現介面的所有成員
    class Program:Imyinterface1,Iman
    {
        string name;
        public string NAME
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        string shiye;
         public string SHIYE
        {
            get
            {
                return shiye;
            }
            set
            {
                shiye = value;
            }
        }
        public void ShowInfo()
        {
            Console.WriteLine("姓名");
            Console.WriteLine(NAME);
            Console.ReadKey();
        }

        public void ManDo()
        {
            Console.WriteLine("子介面iman的方法mando");
        }
        static void Main(string[] args)
        {
            Program p = new Program();
           
            //透過介面物件例項化,呼叫
            Imyinterface1 i1 = p;
            i1.NAME = "zxy";
            i1.ShowInfo();
           
            Iman im1=p;
            im1.NAME = "oth";
            im1.SHIYE = "shiye1";
            im1.ManDo();//例項化介面物件時(子介面時,它有父介面,即介面是繼承關係)


            Program p1 = new Program();
            p1.name = "ha1";
            p1.ShowInfo();

        }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace learninterface1
{
    interface Imyinterface1
    {
        string NAME
        {
            get;
            set;
        }
        void ShowInfo();
    }

    //接品繼承介面,子介面不用重寫父介面的成員,僅編寫新增的成員即可
    interface Iman:Imyinterface1
    {
        string SHIYE
        {
            get;
            set;
        }
        void  ManDo();

    }
}

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-718287/,如需轉載,請註明出處,否則將追究法律責任。

相關文章