命名空间内的命名空间在 C# 中称为嵌套命名空间。这样做主要是为了正确构建您的代码。
我们有一个外部命名空间 -
namespace outer {}
其中,我们在外部命名空间内有一个内部命名空间 -
namespace inner { public class innerClass { public void display() { Console.WriteLine("Inner Namespace"); } } }
现在要调用内部命名空间的方法,设置内部类的类对象并调用该方法,如下例所示 -
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"); } } } }
以上就是C# 中的嵌套命名空间是什么?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号