Home > Backend Development > C#.Net Tutorial > What are nested namespaces in C#?

What are nested namespaces in C#?

王林
Release: 2023-08-29 10:57:02
forward
1146 people have browsed it

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 {}
Copy after login

Among them, we have an internal namespace within the external namespace-

namespace inner {
   public class innerClass {
      public void display() {
         Console.WriteLine("Inner Namespace");
      }
   }

}
Copy after login

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");
         }
      }
   }
}
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template