
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- Can namespaces be nested in C++?
- What are namespaces in C#?
- What are nested classes in C#?
- What are nested structures in C language?
- What are Python namespaces all about?
- What are some of the important namespaces in C#? Provide a brief description of each
- How to define namespaces in C#?
- How to use namespaces in C++?
- What are nested interfaces in Java?
- What are nested rules in LESS?
- What are JavaScript Nested Functions?
- How will you compare namespaces in Python and C++?
- Nested Classes in C#
- Nested Classes in C++
- Nested Tuples in C#

Advertisements