2.Lesson 1: Getting Started with C# #

This lesson will get you started with C# by introducing a few very simple programs. Here are the objectives of this lesson:
• Understand the basic structure of a C# program.
• Obtain a basic familiarization of what a “Namespace” is.
• Obtain a basic understanding of what a Class is.
• Learn what a Main method does.
• Learn how to obtain command-line input.
• Learn about console input/output (I/O).

A Simple C# Program
There are basic elements that all C# executable programs have and that’s what we’ll concentrate on for this first lesson, starting off with a simple C# program.

Warning: C# is case-sensitive.

A Simple Welcome Program: Welcome.cs
// Namespace Declaration

using System;
// Program start class
class WelcomeCSS
   // Main begins program execution.
   staticvoid Main()
       // Write to console
        Console.WriteLine("Welcome to the C# Station Tutorial!"); 

There are 4 primary elements in C# such as:

  • namespace declaration
  • class,
  • a Main method
  • program statement.

Note: The command-line is a window that allows you to run commands and programs by typing the text in manually. It is often refered to as the DOS prompt, which was the operating system people used years ago, before Windows.

The .NET Framework SDK, which is free, uses mostly command line tools. Therefore, I wrote this tutorial so that anyone would be able to use it.

The first thing you should be aware of is that C# is case-sensitive. The word “Main” is not the same as its lower case spelling, “main”.

They are different identifiers. If you are coming from a language that is not case sensitive, this will trip you up several times until you become accustomed to it.

The namespace declaration, using System;, indicates that you are referencing the System namespace. Namespaces contain groups of code that can be called upon by C# programs. With the using System; declaration, you are telling your program that it can reference the code in the System namespace without pre-pending the word System to every reference.

The class declaration, class WelcomeCSS, contains the data and method definitions that your program uses to execute. A class is one of a few different types of elements your program can use to describe objects, such as structs, interfaces , delegates, and enums.

The one method within the WelcomeCSSclass tells what this class will do when executed. The method name, Main, is reserved for the starting point of a program. Main is often called the “entry point” and if you ever receive a compiler error message saying that it can’t find the entry point, it means that you tried to compile an executable program without a Main method.

A static modifier precedes the word Main, meaning that this method works in this specific class only, rather than an instance of the class. This is necessary, because when a program begins, no object instances exist.

Every method must have a return type. In this case it is void, which means that Main does not return a value. Every method also has a parameter list following its name with zero or more parameters between parenthesis. For simplicity, we did not add parameters to Main. Later in this lesson you’ll see what type of parameter the Main method can have. You’ll learn more about methods in Lesson 05: Methods.

The Main method specifies its behavior with the Console.WriteLine(…) statement. Console is a class in the System namespace. WriteLine(…) is a method in the Console class. We use the “.”, dot, operator to separate subordinate program elements. Note that we could also write this statement as System.Console.WriteLine(…).


  • Now you know the basic structure of a C# program.
  • using statements let you reference a namespace and allow code to have shorter and more readable notation.
  • The Main method is the entry point to start a C# program.
  • You can capture command-line input when an application is run by reading items from a string[] (string array) parameter to your Main method.
  • Interactive I/O can be performed with the ReadLine, Write and WriteLine methods of the Console class.
Suggest Edit