HOW TO WRITE AND COMPILE YOUR FIRST C# PROGRAM
Hello everyone, today we’ll learn how to write and compile our first simple program in C# using visual studio.
First of all you have to install visual studio on your desktop. If you don’t installed it yet, please go to the following link to read instruction on how to download and install visual studio (https://msdn.microsoft.com/en-us/library/e2h7fzkw.aspx?f=255&MSPPError=-2147217396)
After downloading and installing open the visual studio and follow the steps below to create and compile your first C# program.
Open start menu, type visual studio and if it is installed on your pc, it will be shown in the result as shown below (I have installed windows 8.1 and visual studio 2013 on my pc.)
Visual studio will be open and you will see a start page in front of you. From the start page click on the New Project under start. If start page is missing, you can alternatively go to the Menu => FILE => New => Project or you can also use keyboard shortcut key Ctrl + Shift + N for opening a dialog to create a new project.
Whatever way you selected to create a new project, a new window will be open from where you can select language of your choice (C#, C++, F# etc.) and type of project you want to create. In this walkthrough we’ll select Visual C# (On the left side) Under Template and then select Console Application.
After that you specify name of your project, the location on your pc where is will be saved (it can be any location) and finally solution name and click OK. To keep things simple our solution name will be same as our project name. But keep in mind that a solution can have multiple projects.
Now, visual studio will create project and you will see an editor where you can write your C# code. Write the following lines in the body of the function Main as in the picture below.Console.WriteLine(“Hello Programmer From Microsoft”);
After writing above lines of code, click on the Start button or use Alt + F5 to build, compile and run your program. Visual studio will build and compile your program and run the program if it has no error. After successfully compiling the program, visual studio will run your program and you will see the output of your first C# program as in the image below.
Congratulations, you are successfully created, write and run your first C# program. Play around with the program, change string Hello Programmer From Microsoft and write anything you would like to write and run the program. But don’t forgot to write your sentences in between “”.