小議C#介面的隱式與顯示實現(續)

來源:互聯網
上載者:User

標籤:blog   http   ar   sp   div   log   html   bs   ef   

上文串連,講的比較模糊,而且調用起來感覺比較混亂

http://www.cnblogs.com/walleyekneel/p/3581489.html

這次改為顯式介面調用,可能項目也有這個一個需求

比如

  public interface IA    {        void Test();    }    public interface IB    {        void Test();    }    public class A : IA, IB    {        public void Test()        {            //TODO:        }    }

這裡面 Test實現的是IA、還是IB呢?這還得看A類型對象而決定?不知道這個理解對不對???

如:

IA a1=new A(); 

Ib a2=new A(); 

 

為了消除這種誤會,我們可以採用定義以下方式

  public class A : IA, IB    {        public void Test()        {        }        void IA.Test()        {                   }        void IB.Test()        {                   }    }

  

 

小議C#介面的隱式與顯示實現(續)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.