C#中預設的修飾符

來源:互聯網
上載者:User

標籤:

參考自Default visibility for C# classes and members (fields, methods, etc)?

Classes and structs that are declared directly within a namespace (in other words, that are not nested within other classes or structs) can be either public or internal. Internal is the default if no access modifier is specified.

直接聲明在命名空間下的類和結構體,預設是internal的。

 

The access level for class members and struct members, including nested classes and structs, is private by default.

類和結構體的成員,包括內嵌的類和結構體,預設是private的

 

interfaces default to internal access.

介面預設是internal的

 

Delegates behave like classes and structs. By default, they have internal access when declared directly within a namespace, and private access when nested.

委託和類以及結構體類似。直接聲明在命名空間下的存取權限預設是internal的。如果內嵌的話,就是private的。

 

Top-level types, which are not nested in other types, can only have internal or public accessibility. The default accessibility for these types is internal.

總結,最高等級的類型(沒有內嵌在其他類型中),只能有internal和public的存取權限。這些類型預設的存取權限是internal

 

然而對於內嵌的類型來說
And for nested types:
Members of Default member accessibility
---------- ----------------------------
enum public       //enum的成員是public的存取權限
class private      //類的成員,預設是private的存取權限
interface public  //介面的成員,預設是private的存取權限
struct private    //結構體的成員,和class類似,預設的存取權限也是private的

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.