Getting Started With C# .Net


Open the Visual C# software from your programs menu. When you first open C# (pronounced C Sharp), you should see a screen something like this (screenshot from the 2019 version of the software):

Visual Studio software

What we're going to do first is to create a very simple programme, so that you can see what makes up a C# .NET project. By the end of this chapter, you'll have learnt the following:

  • How to create new projects
  • What the Solution Explorer is
  • The various files that make up of a C# .NET project
  • How to save your work
  • How to run programmes
  • The importance of the Main statement

The simple programme we'll create is called a Console Application. We won't be doing much else with this type of application, as this is a course about Windows Applications. Off we go then!


A Simple C# Console Application

A Console Application is one that looks like a DOS window. If you don't know what these are, click your Start menu in the bottom left of your screen. In Vista and Windows 7, type cmd in the search box at the bottom of the start menu. In Windows 8 and 10, the search box is on the Start Screen page. You'll then see the search results appear:

CMD search in Windows 7

Click cmd.exe to see the console appear.

Click OK and you'll see a black screen, like this one:

A DOS Window

This is the type of window you'll see for our Console Application. When you create your Windows forms, there's a whole lot of code to get used to. But Console Applications start off fairly simple, and you can see which part of the programme is the most important.

As well as the code, have a look on the right hand side and you'll see the Solution Explorer. This is where all the files for your project are. (If you can't see the Solution Explorer, click View from the C# menu bar at the top. From the View menu, click Solution Explorer.)

The code itself will look very complicated, if you're new to programming. We'll get to it shortly. For now, right click the Program.cs tab at the top, and click Close from the menu that appears:

Close the Program

Or just click the X in the top right corner:

Close Program

Now double click the Program.cs file in the Solution Explorer:

The Solution Explorer in C# Express

When you double click Program.cs, you should see the code reappear. So this code is the programme that will run when anyone starts your application.

Now click the arrow symbol next to Properties in the Solution Explorer above. You'll see the following:

The Properties option in the Solution Explorer

The file called AssemblyInfo.cs contains information about your programme. Double click this file to open it up and see the code. Here's just some of it:

The assembly info file in C# 2017

The reddish colour text is something you can change. You can add a Title, Description, Copyright, Trademark, etc.

But right click the AssemblyInfo.cs tab at the top, and click Close from the menu. Now, in the Solution Explorer, click the plus symbol next to References:

Console Application references

These are references to code built-in to C# (you may see more entries in the Community 2015 and 2017 editions). Much later, you'll see how to add your own files to this section.

In Visual Studio Community 2019, you may also see lines that say references. These will be grey. It's part of a new addition called CodeLens. If you don't want to see these lines, click Tools on the menu bar at the top. From the Tools menu, click on Options at the bottom. You'll see a dialogue box appear. Expand the Text Editor item, then All Languages. Select CodeLens. Deselect the Enable CodeLens option:

Switching off CodeLens in Visual Studio Community 2019

Before we add some code, let's save the project. We'll do that in the next part below.

saving your work in c# .net -->

back to the c# net contents page