Default Class Accessibility in C#

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

by default is a class:

  1. private ?
  2. internal ?
  3. sealed ?
相关标签:
4条回答
  • 2020-12-10 06:24

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

    Accessibility Levels (C#) on MSDN

    0 讨论(0)
  • 2020-12-10 06:34

    internal

    see: http://msdn.microsoft.com/en-us/library/ms173121.aspx

    0 讨论(0)
  • 2020-12-10 06:36

    Also, it is not sealed by default. I believe nested classes are private by default.

    0 讨论(0)
  • 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; }
    
    0 讨论(0)
提交回复
热议问题