

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are nested namespaces in C#?
A namespace inside a namespace is called a nested namespace in C#. This is mainly done to properly structure your code.
We have an outer namespace −
namespace outer {}
Within that, we have an inner namespace inside the outer namespace −
namespace inner { public class innerClass { public void display() { Console.WriteLine("Inner Namespace"); } } }
Now to call the method of inner namespace, set a class object of the inner class and call the method as shown in the below example −
namespace outer { class Program { static void Main(string[] args) { innerClass cls = new innerClass(); Console.WriteLine("Welcome!"); Program.display(); cls.display(); Console.ReadLine(); } public static void display() { Console.WriteLine("Outer Namespace"); } } namespace inner { public class innerClass { public void display() { Console.WriteLine("Inner Namespace"); } } } }
- Related Questions & Answers
- What are namespaces in C#?
- Can namespaces be nested in C++?
- What are Python namespaces all about?
- What are JavaScript Nested Functions?
- What are nested classes in C#?
- What are nested interfaces in Java?
- What are nested structures in C language?
- PHP Namespaces Overview
- PHP Using namespaces
- What are the different types of nested classes are defined in Java?
- What are some of the important namespaces in C#? Provide a brief description of each
- Namespaces and Scoping in Python
- Namespaces and Scope in Python
- PHP Aliasing/Importing namespaces
- PHP Declaring sub-namespaces
Advertisements