Home > Article > Backend Development > What are nested namespaces in C#?
Namespaces within namespaces are called nested namespaces in C#. This is mainly done to structure your code correctly.
We have an external namespace-
namespace outer {}
Among them, we have an internal namespace within the external namespace-
namespace inner { public class innerClass { public void display() { Console.WriteLine("Inner Namespace"); } } }
Now we want to call the method of the internal namespace, Set the class object of the inner class and call the method as shown in the following 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"); } } } }
The above is the detailed content of What are nested namespaces in C#?. For more information, please follow other related articles on the PHP Chinese website!