Is there a use for a void field? [closed] - c#

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

Related

Runtime error with Generics [closed]

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.

windows forms power symbol [closed]

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.
Using Visual Studio 2010, Windows Forms Application. When creating a click event for a button the function parameters are as follows:
(System::Object^ sender, System::EventArgs^ e)
What is the meaning of the power symbol? Google isn't helping me search this as it ignores special characters ><
I know in c# it is an exclusive OR operator but that seems irrelevant here.
That looks like C++, not C#.
Did you see this in the documentation? If so, switch the documentation mode to C# and things will make a lot more sense.
If Visual Studio is generating this, you probably accidentally created a C++ project.

C# method, automatically filling in the parameter list with the default passing [closed]

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);

ArrayList.Item property not found. Using NET Framework 4.0 and Visual Studio 2010 [closed]

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.
For some reason Visual Studio has every property and method of ArrayList except the Item property(it will not appear in the auto complete box). It will not compile when I use it anyway.
The Item property in C# is accessible through the square brackets operator. For example, if the documentation for List<T> says that a class exposes property Item that takes an int and returns a T. You can use it like this:
var res = myList[123];

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 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?

Categories