Export (0) Print
Expand All

Implementing Nested Classes

Visual Studio .NET 2003

If you are developing a complex component, you may need to implement nested classes. Nested classes are classes where the class declaration is fully contained within the class declaration of another class, and are useful for developing object models in your component. For more information on how they can be used, see Nested Classes in Components and Recommendations on Nested Classes in Components.

Implementing nested classes is a trivial matter. Once the class declaration is fully enclosed within another class declaration, the class is considered nested and can only be accessed through the containing class.

To implement a nested class within a containing class

  • Within the class declaration of the containing class, add the class declaration for the nested class. If you have already written the code for the nested class, you may cut and paste it into the class declaration.

    The following example shows how to implement a nested class:

    ' Visual Basic
    ' This class contains the nested class.
    Public Class TheClass
       ' This class is the nested class.
       Private Class NestedClass
       ' Insert code to implement the nested class.
       End Class
       ' Insert code to implement TheClass.
    End Class
    
    // C#
    // This class contains the nested class.
    public class TheClass
    {
       // This is the nested class
       private class NestedClass
       {
          // Insert code to implement NestedClass.
       }
       // Insert code to implement TheClass.
    }
    

See Also

Nested Classes in Components | Recommendations on Nested Classes in Components | Complex Components

Show:
© 2014 Microsoft