O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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>]
						

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required