Welcome to the world of C# and .NET! If you’re just starting out or coming from another language, this guide will help you understand C#, why it’s a great choice, and how to set up your computer to start coding.
By the end, you’ll have a working development environment and will have written your very first C# program.
🎯 What is C#?
C# (pronounced “C-sharp”) is a modern programming language created by Microsoft as part of the .NET ecosystem. It’s used to build everything from web apps, desktop apps, and mobile apps to games and cloud services.
Why choose C#?
- Easy to learn, especially if you know Java, C++, or Python.
- Used by companies big and small, including those building enterprise software, video games (Unity), or web apps.
- Supported across Windows, macOS, and Linux.
🚦 The .NET Ecosystem in Brief
.NET is a platform for building, running, and deploying applications. Here’s what you need to know:
- .NET SDK: The toolkit for building apps (includes the C# compiler, tools, and base libraries).
- .NET Runtime: Lets you run apps built with .NET.
- Cross-platform: Write code once, run it anywhere.
💻 Setting Up Your Environment
1. Install the .NET SDK
Go to dotnet.microsoft.com/download and download the latest LTS version for your operating system. Follow the install instructions for your OS:
- Windows: Download the installer and run it.
- macOS: Use the installer or Homebrew:
brew install --cask dotnet-sdk
- Linux (Ubuntu/Debian):
1 2 3 4
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update sudo apt-get install -y dotnet-sdk-8.0
Verify your install:
Open a terminal (or Command Prompt/PowerShell) and run:
1
dotnet --version
You should see a version number (like 8.0.100
).
2. Choose an Editor or IDE
You can use any text editor, but these are recommended for beginners:
- Visual Studio (Windows): The most full-featured and beginner-friendly.
Download Visual Studio Community Edition - JetBrains Rider (cross-platform): Feature-rich, but paid (free for students).
- Visual Studio Code (cross-platform): Lightweight and free.
Install the “C#” and “.NET” extensions for best results.
Tip: If unsure, start with Visual Studio (Windows) or VS Code (Mac/Linux/Windows).
3. (Optional) Install Git for Version Control
Version control is helpful even for beginners.
- Download Git and follow the installer.
- Set up your name/email:
1 2
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
📝 Write Your First C# Program
Let’s create and run a simple C# console application.
- Open your terminal or command prompt.
- Run:
1 2 3
dotnet new console -n MyFirstApp cd MyFirstApp dotnet run
- You should see
Hello, World!
printed.
Understanding the Code (Program.cs):
1
2
// This is a comment
Console.WriteLine("Hello, World!");
That line prints a message to the screen.
Let’s make it more interactive:
1
2
3
Console.WriteLine("Welcome to C#! What is your name?");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name ?? "stranger"}!");
🌱 What’s Next?
Now that you’re set up:
- Try changing the message or adding more lines to your program.
- Explore the basics: variables, data types, and simple math.
- Don’t worry about making mistakes: experimentation is the best way to learn!
📚 Resources
Recap:
You’ve learned what C# is, installed the tools you need, and written your first code. You’re officially a C# developer… congratulations!
In the next post, we’ll look at configuring your development environment for productivity and comfort.