0

Possible Duplicate:
What are the Default Access Modifiers in C#?

When I define a class in C#, and don't specify any access modifier which one is the default? Is it public or protected?

Community
  • 1
  • 1
Surya sasidhar
  • 29,607
  • 57
  • 139
  • 219

2 Answers2

4

In C# if the type is not nested (within other class or struct) and doesn't have access modifier applied it is internal. If it is nested - private.

From C# specification:

3.5.1 Declared accessibility

...

• Types declared in compilation units or namespaces can have public or internal declared accessibility and default to internal declared accessibility.
• Class members can have any of the five kinds of declared accessibility and default to private declared accessibility. (Note that a type declared as a member of a class can have any of the five kinds of declared accessibility, whereas a type declared as a member of a namespace can have only public or internal declared accessibility.)

Dzmitry Huba
  • 4,493
  • 20
  • 19
  • thanku mr.Dzmitry huba good explanation thank u? i have another doubt about static method, variable, class. how these r different from normal class, method and variables – Surya sasidhar Oct 09 '09 at 08:54
  • In terms of default accessibility they are not different from instance members. – Dzmitry Huba Oct 09 '09 at 09:11
0

It is [internal]

Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61