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

Defining Your Own Namespaces

The syntax for defining a namespace of your own making is straightforward. Simply write the keyword namespace followed by a namespace name you've chosen. Below this header, include a pair of curly braces; they delimit the scope of your namespace. You can then include the classes you want this namespace to contain by writing their definitions between these curly braces. The source code of Listing 15.1 for example, defines a namespace called ElevatorSimulation that contains an Elevator and a Person class. The scope of the ElevatorSimulation namespace spans from line 2 to line 36.

Listing 15.1. Defining the ElevatorSimulation namespace
 01: namespace ElevatorSimulation 02: { 03: using System; 04: 05: class Elevator ...

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