Introduction
C# remains one of the most powerful languages in 2026 for building .NET applications. This tutorial teaches you how to create a complete console application, from an empty project to adding business logic. You'll learn the essential basics while working with real, executable code. Every step is designed to be immediately applicable, whether you're a student or a career changer.
Prerequisites
- .NET SDK 8.0 or higher installed
- A code editor such as Visual Studio Code or Visual Studio
- Basic programming knowledge (variables, functions)
Initialize the project
dotnet new console -n MonPremierProjet
cd MonPremierProjetThis command creates a minimal C# console project. The folder already contains a Program.cs file ready to be modified.
Functional Hello World
using System;
namespace MonPremierProjet;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Bonjour, le monde C# 2026 !");
Console.WriteLine("Appuyez sur une touche pour quitter.");
Console.ReadKey();
}
}This code displays a message and waits for user input. It uses the System namespace and the standard Main method as the entry point.
Add variables
using System;
namespace MonPremierProjet;
class Program
{
static void Main(string[] args)
{
string nom = "Alice";
int age = 28;
double salaire = 2450.75;
Console.WriteLine($"Bonjour {nom}, vous avez {age} ans.");
Console.WriteLine($"Votre salaire est de {salaire} euros.");
Console.ReadKey();
}
}Variables are declared with their type. String interpolation with $ makes it easy to insert values into the displayed text.
Create a simple method
using System;
namespace MonPremierProjet;
class Program
{
static void Main(string[] args)
{
AfficherMessage("Bienvenue dans votre application C#");
Console.ReadKey();
}
static void AfficherMessage(string message)
{
Console.WriteLine(message);
Console.WriteLine("Méthode exécutée avec succès.");
}
}Extracting logic into a method makes the code more readable and reusable. Static methods are ideal for beginners.
Add a business class
namespace MonPremierProjet;
public class Personne
{
public string Nom { get; set; }
public int Age { get; set; }
public Personne(string nom, int age)
{
Nom = nom;
Age = age;
}
public void SePresenter()
{
Console.WriteLine($"Je m'appelle {Nom} et j'ai {Age} ans.");
}
}Creating a separate class organizes code according to the single responsibility principle. This class encapsulates data and behavior.
Use the class in the program
using System;
namespace MonPremierProjet;
class Program
{
static void Main(string[] args)
{
Personne p = new Personne("Lucas", 32);
p.SePresenter();
Console.ReadKey();
}
}Instantiating and calling methods demonstrates how to reuse the Personne class. This pattern is the foundation of object-oriented programming in C#.
Best practices
- Always name variables and methods explicitly
- Separate business logic into dedicated classes
- Use string interpolation instead of concatenation
- Add comments only when the code is not self-documenting
- Run dotnet build regularly to catch errors early
Common mistakes to avoid
- Forgetting the Main entry point or making it non-static
- Not importing required namespaces (using)
- Confusing value and reference types during assignments
- Ignoring compiler error messages before running the program
Go further
Deepen your knowledge with our C# and .NET training.