简体   繁体   English

C# .NET WinForms。 Visual Studio 无法识别子文件夹中的命名空间

[英]C# .NET WinForms. Visual studio won't recognise namespaces in subfolders

When I create a new folder, in this case Model , as a subfolder to the solution directory, and add a class in there, which is wrapped in a namespace, the namespace cannot be found.当我创建一个新文件夹时,在这种情况下Model ,作为解决方案目录的子文件夹,并在其中添加一个类,该类包装在命名空间中,找不到命名空间。

Yes, I have tried both adding a using directive, and referring to the class directly, like Model.Class , from the main source file.是的,我已经尝试添加using指令,并从主源文件中直接引用类,如Model.Class

What is going on?到底是怎么回事? In the class explorer, the Model folder is not visible, while it is visible in the solution explorer, it is visible.在类资源管理器中, Model文件夹不可见,而在解决方案资源管理器中可见,它是可见的。 The other subfolders are visible in the class explorer.其他子文件夹在类资源管理器中可见。

What is the namespace in the class file?类文件中的命名空间是什么?

If you have a class file in the Model.Class folder, but the namespace in the file is Model , you still have to use using Model;如果你在Model.Class文件夹中有一个类文件,但是文件中的命名空间是Model ,你还是要使用using Model;

Problem solved.问题解决了。 The folder and code files in question were not part of the VS project.有问题的文件夹和代码文件不是 VS 项目的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM