標籤:
參考自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#中預設的修飾符