当我尝试从另一个文件导入命名空间时,编译器会给我错误消息"找不到类型或命名空间名称"。看看下面的代码。两个文件都在同一个目录中,所以我不明白出了什么问题。
安装程序.cs(主文件(
using System;
using ScreenTextLine; // Error is here.
namespace Setup
{
namespace Screen
{
class Text
{
static void Main(string[] args) { }
}
}
}
问题.cs(我尝试导入的命名空间的文件(
using System;
namespace Setup
{
namespace ScreenTextLine
{
class WelcomeText
{
static void Main(string[] args){}
}
}
}
在引用它们时,您需要使用以下格式用点分隔每个命名空间,从而使用它们的完全限定名称...
[Top_level_namespace]。[nested_namespace]
所以,这个嵌套结构...
namespace Setup
{
namespace Screen
{
}
}
它被using
语句以这种方式引用......
using Setup.Screen;