C#類修飾符public和internal

來源:互聯網
上載者:User

當在命名空間建了一個類時,預設修飾符號是internal。

作用:在當前命名空間內可以實現對類的調用。

當類的修飾符是public時,表明該類不僅在當前命名空間可以被調用,在其它命名空間也可以被調用。如:

using system;using ...;namespace s1{internal class A{....}        class B        {           A a=new A();//ok        }}

但是 下述代碼則會提示錯誤:

using system;using ...;namespace s1{internal class A{....}        }using system;using ...;using s1;namespace s2{    class B    {       A a=new A();//error,as A is an internal which can only be called in its packet     }}

後繼文章中將寫點關於C++和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.