13.7. More About the Main Method
In Chapter 1, we introduced the Main method as the initial point of execution for a C# program. We'd now like to go into a little more detail on some features and nuances of the Main method.
13.7.1. Main Method Variants
It turns out that there are actually four variations of the Main method header:
The first is the version we introduced in Chapter 1—a parameterless method with a return type of void:
static void Main()
The next version returns a result of type int instead:
static int Main()
Returning an int value is a way to signal to the execution environment (operating system) the status of how the program terminated:
public class Foo { static int Main() { if (something goes awry) { return −1; } else { // All ...
Get Beginning C# 2008 Objects: From Concept to Code now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.