hi
can any one tell me how main method return value and how i use it......?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sam HobbsPosted Jun 9, 2011, 7:13 AM
Note that in addition to the %ERRORLEVEL% environment variable, the Process.ExitCode Property also has the return value of a process, so if you use the Process class then you can get the Main's return value from the Process.ExitCode Property. The exit code is set in other ways by programs written in other languages but most compilers support a way to return a return value. Read the documentation of the Process.ExitCode Property for a little bit more.
VulpesPosted Jun 9, 2011, 5:21 AM
So, if you compile and run this program from the command line:
and then type at the command line:
echo %ERRORLEVEL%
you'll see a value of 1 returned.
This can be used to tell the OS (or another process) whether the program terminated normally or not. By convention 0 is returned for a normal termination (you'll always get this if you use a void return type) and other numbers can be used to indicate various error conditions.
Jaganathan BantheswaranPosted Jun 9, 2011, 4:58 AM
Return type of the Main can be int or void.
Its better to use int.
If you return 0 then OS will know that program has been executed successfully.