我一直在处理一个应用程序,但遇到了一个我以前从未见过的异常错误。我有两个类,一个是 UserControl,一个是 Form,设置如下:
namespace NC
{
public partial class Board : UserControl
{
// stuff
}
}
namespace NC
{
partial class Board
{
// this is the *.designer.cs file
}
}
namespace NC
{
public partial class MainForm : Form
{
// normal form stuff
}
}
namespace NC
{
partial class MainForm
{
// this is the *.designer.cs file. it has a Board added to it.
}
}
它们都包含在同一个项目中,因此应该不是问题。但是,我在编译时得到了这个:
The type name 'Board' does not exist in the type 'NC.NC'
我查看了表单的设计器文件,发现了这个:
this.Board1 = new NC.Board();
我删除了命名空间,它工作正常。每次我访问表单编辑器时,它都会再次添加。我以前从来没有遇到过任何问题。是否有某种设置或我可以更改的内容?
最佳答案
你有一个名为 NC
的类吗?如果这样做,最好将其重命名为其他名称。听起来编译器正在一个名为 NC
的类中寻找 Board,而不是命名空间 NC
...
关于c# - 为什么包含在命名空间中的一个类看不到包含在同一命名空间中的另一个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3348306/