Get to know Namespaces - CSharp Custom Type

CSharp examples for Custom Type:namespace

Introduction

A namespace is a domain for type names.

Types are typically organized into hierarchical namespaces.

For example, the RSA type that handles public key encryption is defined within the following namespace:

System.Security.Cryptography

A namespace forms an integral part of a type's name.

The following code calls RSA's Create method:

System.Security.Cryptography.RSA rsa = System.Security.Cryptography.RSA.Create();

The namespace keyword defines a namespace for types within that block. For example:

namespace Outer.Middle.Inner
{
  class Class1 {}
  class Class2 {}
}

The dots in the namespace indicate a hierarchy of nested namespaces.

The code that follows is semantically identical to the preceding example:

namespace Outer
{
  namespace Middle
  {
    namespace Inner
    {
      class Class1 {}
      class Class2 {}
    }
  }
}

Related Tutorials