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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Jun 9, 2011, 3:13 AM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Jun 9, 2011, 1:21 AM EDT
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 BantheswaranRank #170 · 14.1K reputationPosted Jun 9, 2011, 12:58 AM EDT
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.