Solved

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

Posted on 2003-10-27
2
207 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

17 Experts available now in Live!

Get 1:1 Help Now