The Main Method
Every C# application must have a method named Main defined in one of its classes. It doesn't matter which class contains the method-you can have as many classes as you want in a given application-as long as one class has a method named Main. In addition, this method must be defined as public and static. The public keyword is an access modifierthat tells the C# compiler that anyone can call this method. As you saw in Chapter 1, the static keyword tells the compiler that the Main method is a global method and that the class does not need to be instantiated for the method to be called. This makes sense once you think about it because otherwise the compiler would not know how or when to instantiate your class. Because the method is static, the compiler stores the address of the method as the entry point so that the .NET runtime knows where to begin the execution of your application.
The demos in this chapter show the Main method as returning void and not receiving any arguments. However, you can define your Main method as returning a value as well as taking an array of arguments. These options, as well as how to iterate through the passed arguments to an application's Main method, are covered in Chapter 5, "Classes."