There are many occasions when you need to create an empty project and add classes and methods late to the project. There are many tutorial, which will show you how to create Windows or Web applications, but you rarely see a tutorial building an empty project. This tutorial guides you towards your first C# Empty project step by step. After that I'll show you how to add a class to the project and few members to the class and call this class members from the main method.
Step 1: Create an Empty Project
Select File->New->Project->Visual C# Projects->Empty Project. Select your project name and appropriate directory using Browse button. See Figure 1.
Figure 1.
When you create an empty project, there is no class available in the project.
Step 2: Adding an Empty Class
Right click on the project in Solution Explorer and click Add->Add Class. See Figure 2.
Figure 2.
Add Class option launches Add New Item dialog, where you can select from many items. I select Class option as you can see from Figure 3. Write name of your class and click Open. I put my class name as mcbClass. Click Open here.
Now you have added a class to your project. Visual Studio create a skeleton of the class for you. It looks like here:
using
Now it time to add functionality to your class. I add few methods to this class. As you can see from the following listing, I add Add, Multiply, Subtract, and Sqaure methods to the class.
public
I add Main method to the same namespace just after mcbClass. Now the entire code looks like following listing.
Now build and run project. You can use Ctrl+F5 or Start Without Debugging menu option from the Debug menu. See Figure 4.
Figure 4.
The output of application looks like Figure 5.