Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

732 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