Understanding the Program.cs class

When you create the console application you should see a file called Program.cs in your project. It is important for you to understand about this file because this will become the starting point from where you will begin your C# learning journey.

The Program class

By default when you create the console application Visual Studio creates a Program.cs file in which it creates a class called Program. This class has one function called the Main function. If you are new to programming then you probably do not know the importance of the Main function. The Main function is the entry point to your program. When you run your program the Main function is the first function which starts execution. You can think of the Main function as the Main gate of your program. The computer enters into your program through the Main function.

You see that the Main function is marked static. You will learn about statics in the coming tutorials and then you will be able to understand why the main function is marked as static.

Keep in mind that if you delete the Main function from your project then your project will not run. Therefore when you are learning C# you should not delete the Program.cs file or the Main function. If you delete the Program.cs file by mistake then you will have to write the Main function inside some other class. Your console project does not depend on the Program class, it only depends on the Main function for its execution. So even if you remove the Main function from the Program class and put in some other class your project will have no problems. Try changing the name of the Program class to some other name and you will see that still your project runs properly.

To keep things simple – don’t delete the Program class or the Main function !

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp