DEV Community

Haris Iftikhar
Haris Iftikhar

Posted on

2 2

Namespaces in C#

Namespaces:
A namespace is designed for providing a way to keep one set of
names separate from another.
The class names declared in one namespace does not conflict with
the same class names declared in another.

Defining a Namespace
A namespaces definition begins with the keyword namespace followed by the namespace name as followed:

namespace namespace_name {
  // your code
}

Enter fullscreen mode Exit fullscreen mode

To call the namespace-enabled version of either function or variable, prepend the namespace keyword as followed:

namespace_name.item_name;
Enter fullscreen mode Exit fullscreen mode

Programming Example:
Programming example

Output
Program output

Nested Namespaces:
You can define one namespace inside another namespace as followed:

namespace namespace_name1 {
  // your code
  namespace namespace_name2 {
    // your code
  }
}
Enter fullscreen mode Exit fullscreen mode

Note: You can access members of nested namespace by using the dot (.) operator.

Programming Example:
Programming example

Output
Program output

Another Way
Programming Example

Output
Image description

Image of Docusign

Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up