Your First C# Program
Write and run your first C# program, first as a single file with dotnet run, then as a project in the terminal and in Visual Studio.
Novice · C# · Updated
After this lesson you can
- Run a single C# file with dotnet run
- Create and run a C# console project
Key takeaways
dotnet run hello.csbuilds and runs a single C# file with no project around it: the quickest way to try an idea.dotnet new console -n Namecreates a console project, anddotnet runin its folder runs it.- A project's code is in
Program.cs, and its.csprojfile holds settings such as the .NET version. - Every C# instruction ends with a semicolon
;.
A C# program is a set of instructions, written in a text file, that the computer follows from top to bottom. The .NET SDK you installed during setup turns those instructions into something your computer can run, and runs it.
In this lesson you will run C# in two ways: a single file, which is the quickest way to try an idea, and a project, which is how real apps and your exercises are built.
One file, one command
Open Git Bash and make a folder for this chapter's practice:
mkdir -p ~/bootcamp/csharp-basics
cd ~/bootcamp/csharp-basics
code hello.cs
VS Code opens an empty file named hello.cs. The .cs extension tells .NET that the file holds C# code. Type this line, then save the file with Ctrl+S:
Console.WriteLine("Hello, C#!");
Back in Git Bash, run it:
dotnet run hello.cs
The first run takes a few seconds while .NET builds your program. Then you should see:
Hello, C#!
Here is what that one line does:
Consoleis the terminal window your program runs in.WriteLinewrites a line of text there.- The text in double quotes,
"Hello, C#!", is what gets written. - The semicolon
;ends the instruction. Every C# instruction ends with one.
Change the text, save, and run it again. You can try any idea in this course this way: one file, one command. When a lesson says Try it, this is how.
A C# project
A real app has more than one file, settings, and libraries it uses. A project keeps all of that together in one folder. Make one:
dotnet new console -n FirstProject
cd FirstProject
ls
dotnet new console creates a console app (a program that runs in the terminal), and -n FirstProject names it. You should see:
FirstProject.csproj obj Program.cs
FirstProject.csprojis the project file. It says which version of .NET the project uses and which libraries it needs. You will rarely edit it by hand.Program.csholds the code. Open it and you will find one line:Console.WriteLine("Hello, World!");objis a working folder .NET uses while it builds. You can ignore it.
Run the project from its folder:
dotnet run
Hello, World!
The code in Program.cs is written as top-level statements: instructions at the top of the file, run in order, with nothing around them. That is all a small program needs. Larger programs organize code into classes and methods, which you will meet soon.
The same project in Visual Studio
Visual Studio builds the same kind of project with a few clicks:
- Open Visual Studio 2026 and choose Create a new project.
- Choose Console App (the one marked C#), then Next.
- Set Project name to
FirstAppand choose a Location inside yourbootcampfolder. Click Next. - Make sure Framework shows .NET 10.0. Leave Do not use top-level statements unchecked. Click Create.
- Press Ctrl+F5 (or choose Debug > Start Without Debugging).
A terminal window opens and shows Hello, World!. Press any key to close it.
Visual Studio and dotnet in Git Bash make exactly the same project. Use whichever you like; the exercises in this course work in both.
Check yourself
2 questions to try on the lesson page.
So what
You can now run C# two ways: a single file with dotnet run hello.cs for quick experiments, and a project for anything bigger. Every program in this course starts one of these two ways.