Nested Types

You can define types inside of other types, known as nested types. Nested types have access to the members of their enclosing types as well as to the members of their enclosing type's base class (subject to the normal accessibility conditions, as will be discussed shortly). Listing 2.11 demonstrates their use. This program defines three different object types: Outer, Middle, and Inner. Inner contains the entry point and accesses the enumerations defined in its enclosing types.

Listing 2.11. Nested types
 using System; namespace NestedTypes { class Outer { private enum Day {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; class Middle { private enum Month {January = 1, February, March, April, May, June, July, August, ...

Get Programming in the .NET Environment now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.