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 Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more