It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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?
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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 9 years ago.
Is it possible to encounter Runtime error while using Generics? Could anybody give an
example?
public Someclass<T>
{
int i;
}
In what situation, this implementation can encounter an runtime error? Could anybody show any implementation by which the above class can encounter a runtime error?
The implementation you showed doesn't really do anything, so it, itself, is very unlikely to exhibit any runtime errors (other than a potential OutOfMemoryException on creation if you're out of memory).
If you had other code within the class, it, of course, could exhibit different behavior, and cause other errors to occur. Using this class, as well, could exhibit errors at runtime, but that error would technically be in the code that used the class, not arising from within the class itself, as this class has no methods defining behavior.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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 9 years ago.
I made an typo in a file I was writing and discovered that there is no compiler error on declaring a void field type:
class MyClass
{
object value;
void otherValue; // I would have expected a compiler error
}
The fact that it is allowed implies to me that there is a use for such a field, but I do not know of one. Trying to set it does generate a compile error. So, is there a use for this, or is it some artifact of how the compiler works that has no function?
Edit
Something went wrong with visual studio that it was not compiling (and thus not giving me an error) Restarted it and it gave me the error. This is embarrassing.
And i am 100% sure it is a compiler error
I have tested the code on Visual Studio 2005, 2008, 2010 & 2012 (confirmed by : hvd)
Error Message :
Error 1 Field cannot have void type C:\Users\Mr Master Minded\Documents\Visual Studio 2008\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 31 9 ConsoleApplication1
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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.
I just thought of a feature for Visual studio that would be so cool, that I'm wondering if it already exists. It would be something like hitting Ctrl+tab when you do an open parenthesis after a method, to automatically fill in the passing arguments with whatever they were called in the method... assuming you named things the same way.
Does that exist?
For example, if I had a method:
public static void Foo(int a, int b)
{
}
And then in another location typed out:
Foo(
I would like to see it populated with:
Foo(a, b)
after pressing some keyboard shortcut.
The similiar feature exists in Resharper. Alt+Enter, then choose Generate argument stubs. But it will fill it with default values like foo.Bar(0, 0);
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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.
I'm having problems with making the main class static which was not static when the project started. However when I follow instructions to make the class static and run it, it gives errors
This has no errors:
static class MyStaticClass {}
Could you be more specific?
If by 'main' class you mean the one in which you define your main method, then make sure that all members of that class are also static.
This is kinda speculative at this point, but if you make your class static you'll have to make
all its methods static
all its fields static
all its properties static
just about anything about your class has to be static.
In general, you can't do anything that relies on the class being instanciated.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical 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 12 years ago.
why use of namespace and use keyword and declaration of namespace
Namespaces are used for organizing the types in the code in a logical manner. Imagine the Base Class Library itself, with its many thousands of types, without namespaces. It is simply a tool for making code more structured, much like the ability to create directories in the file system helps you organize your files.
Now, since the full name of a type is the namespace and type name, these may become fairly long. In order to make this easier on you as a developer, you can tell the compiler that you are using types from certain namespaces in a code file with using (or Imports in VB.NET) directives, and then you don't need to use the full name in that file. It simply tells the compiler where to go look for any type that is not entered using the full name in the code.