C# Syntax

Start up Visual Studio IDE. Create a New C# Console Project name it C-SharpSyntax. Once you have created the application you should see code like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)



This is the general structure of a C# Console Project. The using command brings a namespace into scope; a namespace organizes code in to groups (groups of classes, inside classes are methods). When you make large programs it is very likely you might have two conflicting classes, for example class car; however if they are in different namespaces then they will not conflict with each other. Classes and Methods are explained later.

 static void Main(string[] args)
 Your code goes here. This is a code block code blocks are made from open and closing curly braces {}

C# is a case-sensitive language, meaning A and a are two totally different things. C# lines terminate with a semi-colon ( ; ).


  • Single line comments start with two forward slashes //
  • Block comments start with a forward slash and an asterisk and end in the reverse: /* comment here */
  • XML comments start with three forward slashes /// and are very good for documentation purposes.

Organizing Code

It is very important to organize code, especially when giving away your program or if another developer is going to work on it. White space and comments are ignored by the compiler (the thing which translates the code into computer language) so use as much white space and comments as possible. The main ways to organize code is to use comments and regions. Regions are blocks of code and are good for organizing code.


#region "buttons"

All other code would go here!

end region

These will be addressed in later tutorials.

Write Your First Program:

Where it says:

static void Main(string[] args)

between the brackets type:

Console.WriteLine("Welcome to your C# tutorial!");

Hit F5 to debug, or at the top tool bar click debug. You should see a black window with the text:

Welcome to your C# tutorial!

Console.WriteLine is a system method if you comment out using system; right at the top of your document 'Console' will no longer be recognized.


When you build your program, certain files get made. This may seem confusing but it actually isn't. The C-SharpSyntax directory default directory is C:\users\<yourname>\ Documents\Visual Studio\C-sharpSyntax

Inside you will see a file called C-SharpSyntax.sln, which is a Visual Studio Solution file. It stores information about other file locations, and you can open it with notepad to read it.

Next you should see a folder called C-SharpSyntax; inside there are a few more folders and two files. Program.cs is your main source code file and you can open it with notepad. The second file is C-SharpSyntax.csproj, which is a C# Project File. It stores information about where other files are located and is an XML file which can also be opened with notepad.

There is a folder called properties; inside is a file called AssemblyInfo.cs which stores information about the program such as company, author, product name, copyright, trademark, description etc. You can open this with notepad as well.

Finally there are the obj and bin folders. Inside bin is another folder called debug, which is where your program will output. If you go back to Visual Studio and look in solution explorer (on the right or press CTRL + R), there is another folder called references. These are just assembly files (dll files).


  • C# is case-sensitive
  • Single line comments start with //
  • Multiline comments start with /* and end with */
  • XML comments start with ///