views:

125

answers:

3

What is the difference between the internal and private access modifiers in C#?

+11  A: 

internal members are visible to all code in the assembly they are declared in.
(And to other assemblies referenced using the [InternalsVisibleTo] attribute)

private members are visible only to the declaring class. (including nested classes)

For (hopefully) obvious reasons, an outer (non-nested) class cannot be declared private.

To answer the question you forgot to ask, protected members are like private members, but are also visible in all classes that inherit the declaring type. (But only on an expression of at least the type of the current class)

SLaks
+4  A: 

internal is for assembly scope (i.e. only accessible form code in the same .exe or .dll) and
private is for class scope (i.e. accessible only from code in the same class).

mumtaz
+1  A: 

Private members are accessible only within the body of the class or the struct in which they are declared.

Internal types or members are accessible only within files in the same assembly

Arkain