logo search
CSharp_Prog_Guide

Общие сведения о пространствах имен

Пространства имен имеют следующие свойства.

Using Namespaces

Namespaces are heavily used within C# programs in two ways. Firstly, the .NET Framework classes use namespaces to organize its many classes. Secondly, declaring your own namespaces can help control the scope of class and method names in larger programming projects.

Accessing Namespaces

Most C# applications begin with a section of using directives. This section lists the namespaces that the application will be using frequently, and saves the programmer from specifying a fully qualified name every time that a method that is contained within is used.

For example, by including the line:

using System;

At the start of a program, the programmer can use the code:

Console.WriteLine("Hello, World!");

Instead of:

System.Console.WriteLine("Hello, World!");

Namespace Aliases

The using Directive can also be used to create an alias for a namespace. For example, if you are using a previously written namespace that contains nested namespaces, you might want to declare an alias to provide a shorthand way of referencing one in particular, as in the following example:

using Co = Company.Proj.Nested; // define an alias to represent a namespace