Default Class Accessibility in C#

后端 未结 4 832
面向向阳花
面向向阳花 2020-12-10 06:11

by default is a class:

  1. private ?
  2. internal ?
  3. sealed ?
4条回答
  •  旧巷少年郎
    2020-12-10 06:47

    The default for non-nested types is internal. The default for nested types is private. In both cases the default (for classes) is unsealed.

    The general rule for all members is that if you don't specify an access modifier, it's as private as it can be. The single exception for this is properties which can make one part (i.e. the getter or the setter) more private than the overall property by specifying an access modifier, e.g.

    public string Foo { get; private set; }
    

提交回复
热议问题