Setting Up Your Development Environment
Before writing C# code, you need to set up your development environment. This lesson guides you through installing the necessary tools.
What You'll Need
To develop C# applications, you need:
- .NET SDK: The software development kit that includes the C# compiler
- Code Editor: A text editor for writing code (we recommend VS Code)
- Terminal/Command Prompt: For running commands
Installing the .NET SDK
The .NET SDK is essential – it includes everything needed to build and run C# applications.
Step 1: Download .NET SDK
- Visit https://dotnet.microsoft.com/download
- Download the latest .NET SDK (not just the Runtime)
- Run the installer and follow the prompts
Step 2: Verify Installation
Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and run:
bash1dotnet --version
You should see a version number like 8.0.100 or higher.
Also try:
bash1dotnet --info
This displays detailed information about your .NET installation.
Installing Visual Studio Code
VS Code is a free, lightweight code editor with excellent C# support.
Step 1: Download VS Code
- Visit https://code.visualstudio.com
- Download the version for your operating system
- Install and launch VS Code
Step 2: Install C# Extension
- Open VS Code
- Click the Extensions icon in the sidebar (or press
Ctrl+Shift+X) - Search for "C#"
- Install the C# Dev Kit extension by Microsoft
This extension provides:
- Syntax highlighting
- IntelliSense (code completion)
- Debugging support
- Code navigation
Creating Your First Project
Let's create a project to verify everything works.
Step 1: Create a Project Folder
Open your terminal and navigate to where you want to store projects:
bash1cd Documents2mkdir CSharpProjects3cd CSharpProjects
Step 2: Create a Console Application
Run the following command:
bash1dotnet new console -n HelloWorld
This creates a new console application named "HelloWorld".
Step 3: Explore the Project
Navigate into the project folder:
bash1cd HelloWorld
You'll see these files:
HelloWorld.csproj: Project configuration fileProgram.cs: Your C# source code file
Step 4: Open in VS Code
bash1code .
This opens VS Code in the current directory.
Understanding the Project Structure
Open Program.cs in VS Code. You'll see:
csharp1// See https://aka.ms/new-console-template for more information2Console.WriteLine("Hello, World!");
This is the modern "top-level statements" format introduced in C# 9. It's the simplest way to write a C# program.
Running Your Application
From the Terminal
In the terminal, make sure you're in the project folder and run:
bash1dotnet run
You should see:
Hello, World!
From VS Code
- Open the Run and Debug panel (
Ctrl+Shift+D) - Click "Run and Debug"
- Select ".NET Core" if prompted
Alternative: Visual Studio (Full IDE)
For Windows users, Visual Studio Community is a full-featured IDE that includes everything:
- Visit https://visualstudio.microsoft.com
- Download Visual Studio Community (free)
- During installation, select the ".NET desktop development" workload
Visual Studio provides:
- Integrated debugging
- GUI designers
- Database tools
- More advanced features
However, VS Code is sufficient for this course and is cross-platform.
Troubleshooting
"dotnet is not recognized"
The .NET SDK isn't in your PATH. Try:
- Restart your terminal
- Restart your computer
- Reinstall the .NET SDK
VS Code doesn't recognize C#
Make sure you:
- Installed the C# Dev Kit extension
- Opened a folder containing a
.csprojfile - Waited for the extension to initialize
Summary
In this lesson, you:
- Installed the .NET SDK
- Set up VS Code with the C# extension
- Created your first C# console application
- Ran the application using
dotnet run
You're now ready to start writing C# code! In the next lesson, we'll create a more interactive "Hello World" program.