Declaring Namespaces

To declare a new namespace, use the namespace keyword in C#:


The default namespace chosen for new code files in a Visual Studio project is based on a setting specified for the project. This setting, shown in Figure 24.5, gets its default value from the name of the project upon creation. The output assembly name follows this default inferred value, too. It’s considered good practice to reflect the top-level namespace for types defined in an assembly in the assembly’s name. For example, the System.Web assembly (mostly) contains System.Web functionality.

Figure 24.5. Default namespace configuration setting.

Namespaces can ...

Get C# 4.0 Unleashed now with O’Reilly online learning.

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