开发者

Cannot make C# constructor compile [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or r开发者_JS百科hetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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()
            {
            }
    };


[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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜