Solved

void Main() or int Main() with return 0

Posted on 2003-10-27
2
215 Views
Last Modified: 2010-04-16
I once read that in C++ it is better programming practice to use int main() with a return 0 rather than using void main.  Is this true and if so is it true of C# as well?  I have looked at many tutorials on C# and found one that used the int return way.
0
Comment
Question by:chilled2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
SRigney earned 25 total points
ID: 9629289
In my opinion it depends on what you will be doing with your application.

If you are writing anything that will be called from a command line, batch file, or DTS Schedule then using a return value would be better because the return value will be provided to the callers, and allow them to make decisions based on the value.

0 is considered no error any non zero number is considered an error.

If you are just writing a GUI then there would be no difference between return 0 and void main.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9629754
As long the return value is not used it doesn't matter. If your calling from a batch file and returning a result use int main().
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question