Solved

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

Posted on 2003-10-27
2
209 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now