Nested Types

Classes are not restricted to holding data and function members. They can also contain the definitions of types like classes, structs, enums, and interfaces, which then are referred to as nested types. This section only deals with nested classes, but the syntax is so similar and straightforward that it easily can be adjusted to work with the remaining three kinds of types (see the notes in Syntax Box 14.5).

As Syntax Box 14.5 shows, a class is nested inside an outer class by simply writing the class header and its associated block as usual, but inside the block of the outer class.

Syntax Box 14.5 The Nested Class

						[<Access_modifier>] class <Identifier_outer_class>
{
    [<Outer_class_data_members>]
						[<Outer_class_function_members>]
						

Get C# Primer Plus now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.