Master C# Programming From Scratch

Clear, interactive, and structured coding lessons designed for absolute beginners.

Module 1: Introduction & Environment Setup

Your First C# Program

To create your very first program in .NET, you will make a Console Application. This is a simple program that runs in a text window (terminal) and prints a message on the screen.

Here is how to create, understand, and run your first program using the VS Code and .NET CLI .

Creating and running your first program in Visual Studio is easy because the software handles the background work for you. Here is the step-by-step guide to doing it in the full Visual Studio IDE on Windows.

Step 1: Create a New Project

  1. Open Visual Studio
  2. On the startup screen, click Create a new project on the right side.
  3. In the search bar at the top, type Console
  4. Select Console App (make sure it has the C# logo next to it), then click Next
  5. Give your project a name (like MyFirstApp) and click Next
  6. Choose the latest .NET version listed (like .NET 8.0 or .NET 9.0 or .NET 10.0) and click Create.

Step 2: Understand the Code

Visual Studio will automatically open a file called Program.cs. Inside, you will see this single line of code:

Static Code Layout Reference
Console.WriteLine("Hello, World!");

  • Console: This means the text window on your screen.
  • .WriteLine: This tells the computer to "write a line of text."
  • ("Hello, World!"): This is the exact message the computer will show.
  • ; (Semicolon): This acts like a period at the end of a sentence. It tells the computer the instruction is over.

Step 3: Run the Program

  1. Look at the top toolbar in Visual Studio. Find the green play button that says MyFirstApp (or has the name of your project).
  2. Click that green play button (or press the F5 key on your keyboard).
  3. A black text window (the console) will pop up on your screen, display Hello, World!, and stay open so you can see it.
  4. Press any key on your keyboard to close the window.

Step 4: Change the Message

Static Code Layout Reference
Console.WriteLine("Welcome to CIIT Training Institute");

Click the green play button again, and you will see your new message on the screen!

With .Net CLI

Step 1: Create the Program

  1. Open your terminal or Command Prompt
  2. Type the below command to create a new folder and project:
    Static Code Layout Reference
    dotnet new console -n MyFirstProgram
  3. Move into your new project folder
    Static Code Layout Reference
    cd MyFirstProgram
  4. Open this folder in VS Code by typing
    Static Code Layout Reference
    code .

Step 2: Look at the Code

  • Inside VS Code, you will see a file named Program.cs. Click to open it. By default, .NET creates a simple one-line program for you that looks like this:

    Static Code Layout Reference
    Console.WriteLine("Welcome to CIIT Training Institute");

Step 3: Run the Program

  1. Go back to your terminal (or open the built-in terminal inside VS Code by pressing `Ctrl + ``).

  2. Type the run command

    Static Code Layout Reference
    dotnet run

  3. Press Enter. The computer will compile (translate) your code and output

    Static Code Layout Reference
    Welcome to CIIT Training Institute