无法使 C# 构造函数编译
每当我尝试应用自己的构造函数而不是 VS 2010 中的默认构造函数时,我都会收到编译器错误: 错误 1 命名空间“全局命名空间”已经包含“任何”的定义
作为一个例子,编译器不会让我这样做:
public class whatever
{
public whatever()
{
}
};
Whenever i try to apply my own constructor instead of the default one in VS 2010 I get the compiler error:
Error 1 The namespace 'global namespace' already contains a definition for 'whatever'
Just as an example the compiler will not let me do this:
public class whatever
{
public whatever()
{
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
[评论帮助OP解决了问题。解决方案在这里。]
该类在解决方案中另一个文件的同一命名空间中再次声明。确保重命名或删除任何此类类,并且一切都应该可以正常编译。
[Comments helped the OP solve the problem. Solution is here.]
The class is declared again in the same namespace in another file in your solution. Make sure that any such classes are renamed or removed, and everything should compile just fine.
在 C# 中,类声明和定义不是分开的(与 C++ 不同),因此类声明后不需要分号。
编辑
这个错误与分号无关,只是我突然想到的。我必须假设您的类是在同一名称空间的其他地方定义的。 “whatever”真的是您要创建的类的名称吗?
In C# the class declaration and the definition are not separated (unlike C++) so you don't need a semi-colon after your class declaration.
edit
That error has nothing to do with the sem-colon, it was just something that jumped out at me. I would have to assume that your class was defined somewhere else in the same namespace. Is "whatever" really the name of the class you are trying to create?