Day 1: Introduction to C# & .NET setup
Welcome to Day 1 of your 30-day journey into C# and ASP.NET Core.
If you’re coming from JavaScript, Python, or Ruby, stepping into the compiled, strongly typed world of C# might seem intimidating. But modern C# (.NET 8 and beyond) is incredibly fast, expressive, and a joy to write. It runs everywhere: Windows, Linux, Mac, and the cloud.
Today we’ll write our first program.
Setup
First, let’s get our tools. You need the .NET SDK.
- Head over to dotnet.microsoft.com/download
- Download and install the latest .NET SDK (e.g., .NET 8 or newer).
- Open a terminal and run
dotnet --versionto ensure it installed correctly.
For your editor, Visual Studio Code (VS Code) with the C# Dev Kit extension is strictly recommended for modern cross-platform development.
Your First App
We will create a simple console application.
Open your terminal in an empty folder and run:
dotnet new console -n HelloWorld
cd HelloWorld
Open this folder in VS Code. You’ll see a Program.cs file.
Program.cs
Thanks to Top-Level Statements in modern C#, your Program.cs file doesn’t need all the boilerplate classes and methods it used to. It’s just one line!
// Program.cs
Console.WriteLine("Hello, World!");
Running It
To run the application, type this in the terminal:
dotnet run
You should see Hello, World! printed to the screen!
Analyzing the anatomy
What actually happened here?
dotnet runtriggered the compiler (Roslyn).- The code was compiled into an Intermediate Language (IL) inside a
.dllfile. - The .NET Runtime took that IL, compiled it down to machine code instantly (Just-In-Time compiling), and ran it.
Console is a class built into .NET, and WriteLine is a method on that class that prints a string and a new line to the standard output.
Challenge for Day 1
- Modify the
Program.csto ask for the user’s name usingConsole.ReadLine(). - Print out a personalized greeting using String Interpolation (e.g.
$"Hello {name}!").
Tomorrow: Variables, Types and Type Conversion.