Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Class Accessibility in C#

Tags:

c#

oop

by default is a class:

  1. private ?
  2. internal ?
  3. sealed ?
like image 753
leora Avatar asked Dec 07 '08 04:12

leora


2 Answers

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; }
like image 200
Jon Skeet Avatar answered Sep 30 '22 18:09

Jon Skeet


internal

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

like image 40
JoelFan Avatar answered Sep 30 '22 17:09

JoelFan