首页 > 解决方案 > 如何使用自定义命名空间?

问题描述

这是我的项目树:

.
├── Human.cs
└── main.cs

这是我的 main.cs:

using Human;
namespace HelloWorldApplication
{
   class HelloWorld
   {
      static void Main(string[] args)
      { 
         Human.Man.sayHi();
      }
   }
}

这是我的 Human.cs:

using System;
namespace Human
{
    class Man{
        public static void sayHi(){
            Console.WriteLine("man is saying 'hi'");
        }
    }
}

我想在我的 main.cs 中使用 Human。我发现的 MSDN 文档没有显示如何导入自定义命名空间。

当我尝试编译 main.cs 时,它会抛出main.cs(2,7): error CS0246: The type or namespace nameHuman' 找不到。您是否缺少程序集参考?`

标签: c#namespaces

解决方案


推荐阅读