method without access modifier

前端 未结 8 957
走了就别回头了
走了就别回头了 2020-12-05 22:21

Ok this is bugging me.. I know I\'ve read it somewhere and google isn\'t helping.

What is the accessibility level of a method that does not specify an access modifie

8条回答
  •  独厮守ぢ
    2020-12-05 23:22

    From The C# Programming Language, Third Edition by Anders Hejlsberg et al, section 10.3.5 ("Class Members - Access Modifiers") on page 434:

    A class-member-declaration can have any one of the five possible kinds of declared accessibility (§3.5.1): public, protected internal, protected, internal, or private. Except for the protected internal combination, it is a compile-time error to specify more than one access modifier. When a class-member-declaration does not include any access modifiers, private is assumed. [Emphasis mine]

    And then in section 11.2 ("Struct Members") on page 539:

    Except for the differences noted in §11.3, the descriptions of class members provided in §10.3 through §10.14 apply to struct members as well.

    Section 11.3 does not mention anything about access modifiers, so my reading of this implies that members of a struct without an access modifier are also private by default. This corresponds with what MSDN says and with my own experience.

提交回复
热议问题