[Previous] [Contents] [Next]

Return Values

Most examples in this book define Main as follows: -

class SomeClass
{
    image
public static void Main()
{
    image
}
    image
}

However, you can also define Main to return a value of type int. Although not common in GUI applications, this can be useful when you're writing console applications that are designed to be run in batch. The return statement terminates execution of the method and the returned value is used as an error level to the calling application or batch file to indicate user-defined success or failure. To do this, use the following prototype: -

public static int Main()
{
image
    // Return some value of type int
    // that represents success or value.
    return 0;
}

[Previous] [Contents] [Next]