Click here to Skip to main content
14,979,837 members
Please Sign up or sign in to vote.
4.80/5 (5 votes)
See more:
why not we can use other return type in Main() except int or void please....
Posted
Updated 25-Oct-10 3:25am
v2

Traditionally DOS (and then windows) apps returned an integer value to say "success" (zero), or "failed" (non-zero error code).
You can still return this - the debugger shows this value if you look at the Output tab when your program completes.
You don't have to return an int: a void is the equivalent of a zero.

There is no facility for any other return format for historical reasons - anything else would be effectively a pointer, and treated as a non-zero error code.
   
Comments
AshishKr 25-Oct-10 9:35am
   
Thanks
Nish Nishant 25-Oct-10 9:42am
   
My vote of 5. Excellent reply.
Dalek Dave 25-Oct-10 10:47am
   
Good Answer, Griff.
Main is starting point of any application in C#. It is run under main thread. Then what should it return and most important whom it return.

There no client waiting for main to finished

So the return type is void

:)
   
v2
Comments
OriginalGriff 25-Oct-10 9:48am
   
That turns out to be wrong: Main always returns an int, even if you specify a void return. You can check this value to see what happened to the process in other C# apps if you need to. See MSDN on Process.ExitCode (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode.aspx)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900