The Main() Function Can Return an int

Instead of returning void, Main() can return an integer value, which can then be read by the calling program or script.  Notice that the return type of the function is an int


1
2
3
4
5
6
7
8
9
10
11
12
class Program
{
    static int Main()
    {
        Console.WriteLine("Doing something..");
 
        if (DateTime.Today.DayOfWeek == DayOfWeek.Monday)
            return -1;     // Monday is bad
        else
            return 0;
    }
}