1

In both C and C++ the main function is of type int and at the end of the main method it returns 0. If the program returns 0 I know that the program was successful. But in c# the main is of type void by default (I guess you could change it to an int and return 0 aswell) so how can I know that the program was successful in this case? Do I have to debug or do some debug writelines to really clarify that the program was successfull in this case where the main method is void?

Jacce
  • 172
  • 1
  • 2
  • 11
  • Know that your program was successful from where? – Haytam Jul 04 '18 at 23:13
  • 3
    [The `Environment.Exit` method takes one parameter, which becomes the process exit code.](https://msdn.microsoft.com/en-us/library/system.environment.exit.aspx) – Ben Voigt Jul 04 '18 at 23:25
  • More discussion on Environment.Exit .. https://stackoverflow.com/questions/155610/how-do-i-specify-the-exit-code-of-a-console-application-in-net – Sql Surfer Jul 05 '18 at 01:11

1 Answers1

6

The Main method can return void or an int:

static int Main()
{
    //... 
    return 0;
}

See the docs.

DavidG
  • 113,891
  • 12
  • 217
  • 223