c# – The “Main” method

In most case a c# file (aka .cs) will contain several (or hundreds of classes). After you have compiled it into an .exe file and double click on it. c# will need to know which part of the c# code needs to run first. You may some a code block in one of your classes that you want to run first when someone double clicks on the exe. But how do you identify this code block to c#?


You can find all my latest posts on medium.

That’s where the main method comes into play. In your cs file, you need to add a special method called the “Main” method to only one of your classes. The code in the main method will be executed someone double clicks on the exe file. The class that houses the main method can be thought of as the “primary class” or the “main class”. The main method hence acts as your applications entry point.