Kaganapan
Mar 17, 9 PM - Mar 21, 10 AM
Sumali sa serye ng meetup upang bumuo ng mga scalable AI solusyon batay sa mga kaso ng paggamit ng tunay na mundo sa mga kapwa developer at eksperto.
Magparehistro naHindi na suportado ang browser na ito.
Mag-upgrade sa Microsoft Edge para samantalahin ang mga pinakabagong tampok, update sa seguridad, at teknikal na suporta.
A type defined within a class, struct, or interface is called a nested type. For example
public class Container
{
class Nested
{
Nested() { }
}
}
Regardless of whether the outer type is a class, interface, or struct, nested types default to private; they are accessible only from their containing type. In the previous example, the Nested
class is inaccessible to external types.
You can also specify an access modifier to define the accessibility of a nested type, as follows:
Nested types of a class can be public, protected, internal, protected internal, private or private protected.
However, defining a protected
, protected internal
or private protected
nested class inside a sealed class generates compiler warning CS0628, "new protected member declared in sealed class."
Also be aware that making a nested type externally visible violates the code quality rule CA1034 "Nested types should not be visible".
Nested types of a struct can be public, internal, or private.
The following example makes the Nested
class public:
public class Container
{
public class Nested
{
Nested() { }
}
}
The nested, or inner, type can access the containing, or outer, type. To access the containing type, pass it as an argument to the constructor of the nested type. For example:
public class Container
{
public class Nested
{
private Container? parent;
public Nested()
{
}
public Nested(Container parent)
{
this.parent = parent;
}
}
}
A nested type has access to all of the members that are accessible to its containing type. It can access private and protected members of the containing type, including any inherited protected members.
In the previous declaration, the full name of class Nested
is Container.Nested
. This is the name used to create a new instance of the nested class, as follows:
Container.Nested nest = new Container.Nested();
Feedback sa .NET
Ang .NET ay isang open source na project. Pumili ng link para magbibigay ng feedback:
Kaganapan
Mar 17, 9 PM - Mar 21, 10 AM
Sumali sa serye ng meetup upang bumuo ng mga scalable AI solusyon batay sa mga kaso ng paggamit ng tunay na mundo sa mga kapwa developer at eksperto.
Magparehistro naPagsasanay
Module
Manage Class Implementations - Training
Learn how to implement classes using advanced techniques like static classes, partial classes, and object initializers that can improve the readability, maintainability, and organization of your code.
Dokumentasyon
sealed modifier - C# reference
sealed modifier - C# Reference
All types and type members in C# have an accessibility level that controls whether they can be used from other code. Review this list of access modifiers.
A property in C# is a member that uses accessor methods to read, write, or compute the value of a private field as if it were a public data member.