C# for Beginners: Install .NET and Write Your First Program
Introduction
C# is a modern, strongly typed language used for web apps, desktop software, games, and cloud services, all built on the .NET platform. This tutorial walks through installing the .NET SDK and creating and running your first console program.
Prerequisites
- A computer running Windows, macOS, or Linux
- Access to a terminal or command prompt
- A code editor such as Visual Studio Code
Step-by-Step Guide
Step 1: Install the .NET SDK
Download and install the .NET SDK from dotnet.microsoft.com. Choose a current long-term support (LTS) release such as .NET 8. The SDK includes the compiler, the runtime, and the dotnet command-line tool.
Step 2: Verify the installation
Open a new terminal and check that the dotnet command is available.
dotnet --versionStep 3: Create a console project
The dotnet CLI generates a ready-to-run project from a template.
dotnet new console -n HelloCSharp
cd HelloCSharpStep 4: Look at the code
Open Program.cs. Modern templates use top-level statements, so you can write code without declaring a class or Main method first.
Console.WriteLine("Hello, CaliberTek!");Step 5: Build and run
dotnet run compiles the project and starts it in one step.
dotnet runFAQs
- What is the difference between .NET and C#?
- C# is the programming language. .NET is the platform that provides the runtime, class libraries, and tools for running C# (and other) programs.
- Can I use C# on macOS and Linux?
- Yes. Modern .NET is cross-platform, so the same C# code runs on Windows, macOS, and Linux.
Summary
With the .NET SDK installed, dotnet new and dotnet run are all you need to start experimenting. Next, learn variables and types, then classes and collections.
Comments
Log in or create a free account to join the discussion.