We saw in the “Set Environment” lesson, how to install Microsoft Visual Studio 2017.
After installing Visual Studio successfully, now let us see how to create a new project and run first program. We will create C# Console Application project.
Open Visual Studio and go to “File” > “New” > “Project”:
Figure 15: Create a new project in C#
Now, “New Project” dialog box will open.
From the left tab, select “Visual C#” and then select “Console App (.NET Framework)” to create a Console Application.
Figure 16: Select Console App (.NET Framework) to create Console Application
After selecting, add the name of the project, set the location and click OK.
Above, we have set the default name and location as:
Name: ConsoleApp1
Location: C:\users\amit_\source\repos
Change the location, if you wish, using the “Browse” button on the right. With that, you can also change the name of the console application.
After adding the name and other details, click OK to start creating the project as shown below.
Figure 17: The project initiates in Visual Studio
As shown in the above screenshot, the project is being created.
After some seconds, the project will be created successfully and “Program.cs” file would be visible as shown below.
Figure 18: Project created successfully
As shown above, the default code is visible. Now let us understand it and do some changes.
Let us add some lines to the “Program.cs” file and display it as shown below:
Program.cs
Source Code: First program in C#
using System; namespace ConsoleApp1 { class Example { static void Main(string[] args) { Console.WriteLine("Hello World"); Console.ReadLine(); } } }
Here,
The same code is added in the Visual Studio IDE project we created:
Figure 19: Added some code in Visual Studio IDE C# Console Application
Now, let’s see how to run the project and display the result. Run any C# Console Application using the following two options:
Both of the above options will run the program.
To find the “Start” button, refer the below screenshot:
Figure 19: Click Start button to run the project
On clicking “Start”, the program runs and the following console is visible that displays the result “Hello World”:
Figure 20: Output of the Console Application
Follow the above steps to run your first program in C#.
Avery good write-up. Please let me know what are the types of C# libraries used for AI development.
very satisfied!!
Good tutorial. Small question: Say, there is : enum numbers { one, two, three} and a string field_enum ="one" how would I from the variable field_enum have a response with value numbers.one so that it can be treated as an enum and not as a string. making a list from the enum, and loop into the list. is not elegant... and may not work is forced value on field is forced ( one = 100).
Hi Team Knowledge Hut, Thank you for such an informative post like this. I am completely new to this digital marketing field and do not have much idea about this, but your post has become a supportive pillar for me. After reading the blog I would expect to read more about the topic. I wish to get connected with you always to have updates on these sorts of ideas. Regards, Kshitiz
The reason abstraction can be used with this example is because, the triangle, circle. Square etc can be defined as a shape, for example.....shape c = new circle(5,0)...the abstract object c now points at the circle class. Thus hiding implementation
Leave a Reply
Your email address will not be published. Required fields are marked *