程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#中默認的修飾符,

C#中默認的修飾符,

編輯:C#入門知識

C#中默認的修飾符,


參考自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  //接口的成員,默認是public的訪問權限
struct private    //結構體的成員,和class類似,默認的訪問權限也是private的

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved