I can't change static void Main(string[] args) in console application. Can anyone please tell me how to change it to anything else?
-
2What do you mean? Does it fail to compile when you change it?– R. Martinho FernandesApr 13, 2011 at 9:11
-
2could you please clarify what you mean by "change static void main"?– AbdouMoumenApr 13, 2011 at 9:12
-
7You can change it to something else. Just use your keyboard. Problem is your program won't compile or start anymore.– H HApr 13, 2011 at 9:12
2 Answers
If you mean you can't change it to be non-static, or you can't change the name of it, that's right: the entry point for an application:
- must be called
Main
- must be static
- must either be parameterless or have a single parameter of type
string[]
- must have a return type of
void
orint
.
What are you trying to change, and why?
-
1@user705641: So put a break-point in and start the debugger. You don't need to change the signature in order to do that. It's really unclear what you're trying to change and what happens when you try to change it. Apr 13, 2011 at 9:21
-
i was just wondering, why run-time needs Main to be static. Obviously, if it is not, then run-time will have to instantiate object of the containing class and then invoke, containingObject.Main(..) . Since containingClass is user-defined and run-time doesnt want to be involved with different case with every other program, so it pre-defines requirement of Main to be static, so that it can be simply called without any dependencies. May 8, 2011 at 20:15
-
@Munish: I think you've answered your own question, pretty much. It's easier for the Main method to control the creation of an object if it definitely wants to, and if it doesn't need to it would be pointless creating one. May 8, 2011 at 20:20
If you change the 'static' from the 'static void main' from the program, the application will be unable to debug, and if put string[] args or not nothing will be happen.