Namespace (C#)

A namespace is a named container that groups related classes and other types to keep code organized and avoid name clashes. The .NET library itself is organized into namespaces like System and System.Collections.

C#

You declare a namespace with the namespace keyword and access types inside it using a dot, or import the whole namespace with a using directive.

Namespaces are like folders for your types: two different namespaces can both contain a class named 'Logger' without conflict.

Syntax

namespace MyApp;

Examples

C#

namespace Shapes;

public class Circle
{
    public double Radius;
}

Learn it in a lesson

See also

Back to the Dictionary