枚举范围声明错误
我有带有枚举的命名空间:
namespace Search
{
enum SearchConditionType
{
Like = 0,
EqualNotString = 1,
EqualString = 2
};
}
然后我尝试声明枚举:
namespace Search
{
public partial class Controls_SelectYesNo : System.Web.UI.UserControl
{
public SearchConditionType Field;
...
并收到错误:
类型或命名空间名称 '' 可以 找不到(您是否缺少使用 指令还是程序集引用?)
出了什么问题?
I have namespace with enums:
namespace Search
{
enum SearchConditionType
{
Like = 0,
EqualNotString = 1,
EqualString = 2
};
}
Then I try to declare enum:
namespace Search
{
public partial class Controls_SelectYesNo : System.Web.UI.UserControl
{
public SearchConditionType Field;
...
And got an error:
The type or namespace name '' could
not be found (are you missing a using
directive or an assembly reference?)
What is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的枚举不是公开的。
Your enum is not public.
将枚举设置为
public
:在 C# 中,没有访问修饰符的类型默认为
internal
。如果文件位于不同的程序集中,则需要添加对包含枚举的程序集的引用。这可以通过解决方案资源管理器中项目的
References
节点来完成。Make the enum
public
:Types that do not have an access modifier default to
internal
in C#.If the files are in different assemblies, you need to add a reference to the assembly containingn the enum. This can be done through the
References
node of the project in the Solution Explorer.嗯...您正在尝试将内部类型公开为公共类型。这是我在你的代码中看到的唯一问题。但它不应该导致您提供的编译器错误,所以我想问题可能出在代码的其他地方。
编辑:您是否试图在另一个程序集中公开枚举?这会导致您列出的错误。所以,是的,只需将枚举公开即可。
Hmm... you are attempting to expose an internal type as a public type. That's the only problem I see with your code. But it shouldn't cause the compiler error you're providing, so I'm thinking maybe the problem is elsewhere in your code.
edit: Are you trying to expose the enum in another assembly? That'd cause the error you're listing. So, yeah, just make the enum public.
接下来的问题是:我从网站制作了一个网络应用程序。在网站中,枚举位于 App_Code 文件夹中。当我重命名该文件夹时,问题就消失了。
Problem was in next: I made a web application from web site. In web site enums was situated in App_Code folder. When I rename this folder - problem disappears.