Nested types have free access to members of the outer type, regardless of whether those members are private. Outer type if you want to access nested types, you are restricted by access rules.
Nested types default to private, regardless of whether the outer layer is a class or struct, but can be set to public, protected internal, protected, internal, or private.
Nested types default to private, regardless of whether the outer type is type or structure, but can be set to public, protected internal, protected, internal, or private.
If the nested type is private or protected, the type of the nested type other than the outer layer type is inaccessible, and another nested type in the external type can access it, but it cannot use its private or protected members. If a member in a nested type is set to public or internal, the outer type and other nested types declared by the same outer type can access those members of the nested type, but those members are still hidden outside the outer layer type.
If the nested type is public or internal, it will be similar to a normal type, and other types can use Morthtype.sontype as normal, but the nested type is still free to access all members of the outer type. In fact, this gives a type a strong accessibility, but also exposes a type of private members, which destroys the encapsulation of the type. In this case, the outer type functions as a namespace, which also gives the ability to type some namespaces.
The original example is as follows:
[Start citation]
A static constructor for a nested class does not initialize with the triggering of an external class. As a result, it is possible to avoid the initialization time of creation, and when an inline class is required, the nested class starts initializing before it begins to initialize.
public class Outside
{
Static Outside ()
{
Console.WriteLine ("Outside inilizlized");
}
public void Sayit ()
{
Nested.run ();
}
Private Class Nested
{
Static Nested ()
{
Console.WriteLine ("Nested initilized");
}
public static void Run ()
{
Console.WriteLine ("Nested Run");
}
}
}
Execution results
Outside o = new Outside ();//print "Outside inilizlized"
Console.ReadLine ();
O.sayit ();//print "Nested initilized" and print "Nested Run" first
Console.ReadLine ();
Nested types (what is??) )