01. Getting Started with C#
C# is a statically-typed language built by Microsoft, used everywhere from games (Unity) and web (ASP.NET) to desktop and mobile. In this lecture you'll install the .NET 8 SDK, create a console project, and run it yourself.
What you'll learn
- 1Understand what .NET 8 LTS means and the difference between SDK and Runtime
- 2Pick one of the IDEs (Visual Studio / VS Code / Rider) and install it
- 3Create your first project with `dotnet new console`
- 4Run it with `dotnet run` and check the output
- 5Do simple I/O with `Console.WriteLine` / `Console.ReadLine`
Overview
C# is a statically-typed language built by Microsoft, used everywhere from games (Unity) and web (ASP.NET) to desktop and mobile. In this lecture you'll install the .NET 8 SDK, create a console project, and run it yourself.
Core Concepts
1) What is .NET?
**.NET** is the runtime + standard library + SDK bundle that runs languages like C#, F#, and VB.NET. Code you write once can run on Windows, macOS, and Linux.
- **.NET 8 LTS**: the Long Term Support release published in November 2023. Officially supported until November 2026.
- **SDK**: the compiler and tool set needed for development (includes the `dotnet` CLI)
- **Runtime**: the minimum components needed just to run a built program
2) Verifying the SDK install
After installing, run the following in a terminal.
dotnet --version
# example output: 8.0.xxxIf it starts with `8.0`, you're good. If the command isn't found, grab the **.NET 8 SDK** from [https://dotnet.microsoft.com/download](https://dotnet.microsoft.com/download).
3) Choosing an IDE
- **Visual Studio 2022 (Windows)** β heavy but the most integrated experience
- **VS Code + C# Dev Kit (cross-platform)** β light and fast, recommended
- **JetBrains Rider** β paid but with great refactoring
This course is IDE-agnostic. Whichever you pick, behavior via the `dotnet` CLI is identical.
4) Creating your first project
dotnet new console -o HelloApp
cd HelloApp
dotnet run- `dotnet new console`: creates a console-app template
- `-o HelloApp`: generates it inside a `HelloApp` folder
- `dotnet run`: builds (auto-`restore` if needed) β runs
On the first run, it prints `Hello, World!`.
5) Top-level statements
Since .NET 6 you can skip the `Main` method and write code directly.
// Program.cs
Console.WriteLine("Hello!");`Console.WriteLine` prints with a trailing newline, `Console.Write` prints without one.
Examples
Example 1 β `HelloApp/Program.cs`: the most basic
// Your first C# program
Console.WriteLine("Hello, C# !");**Output**
Hello, C# !**Note:** Don't forget the semicolon (`;`). C# delimits statements with `;`, not newlines.
Example 2 β `Echo/Program.cs`: take input and greet
Console.Write("Enter your name: ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");**Output**
Enter your name: Alex
Hello, Alex!**Note:** `Console.ReadLine()` can return `null` if there is no input, so its type is `string?`. (More on this in lecture 2.)
Example 3 β `MultiPrint/Program.cs`: multiple lines + string interpolation
string product = "Apple";
int count = 3;
int price = 1500;
Console.WriteLine("=== Purchase summary ===");
Console.WriteLine($"Product: {product}");
Console.WriteLine($"Quantity: {count}");
Console.WriteLine($"Total: {count * price} won");**Output**
=== Purchase summary ===
Product: Apple
Quantity: 3
Total: 4500 won**Note:** The `{ }` inside `$"..."` can hold any expression. This is called **string interpolation**.
Full example code (src/)
src/Echo/Echo.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodingNow.Lecture.Basics01</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
src/Echo/Program.cs
// Greet the user by name
Console.Write("Enter your name: ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");
src/HelloApp/HelloApp.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodingNow.Lecture.Basics01</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
src/HelloApp/Program.cs
// Your first C# program
Console.WriteLine("Hello, C# !");
src/MultiPrint/MultiPrint.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodingNow.Lecture.Basics01</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
src/MultiPrint/Program.cs
// Multiple lines + string interpolation
string product = "Apple";
int count = 3;
int price = 1500;
Console.WriteLine("=== Purchase summary ===");
Console.WriteLine($"Product: {product}");
Console.WriteLine($"Quantity: {count}");
Console.WriteLine($"Total: {count * price} won");
Common Mistakes
- Writing `Console.Writeline` with the wrong casing β C# is **case-sensitive**.
- Forgetting the trailing `;` β compile error.
- Writing `"{name}"` without the `$` β the literal `{name}` is printed.
- Running `dotnet run` outside the project folder and getting a "project not found" error.
- Confusing `.NET Framework 4.x` with `.NET 8` β this course targets **.NET 8** (the Core line).
Summary
- Install the .NET 8 SDK and verify with `dotnet --version`
- The basic flow is `dotnet new console -o name` β `dotnet run`
- Use `Console.WriteLine` to output and `Console.ReadLine` to read input
- Use `$"..."` string interpolation to inject variables cleanly
Practice
**Practice - 01. Getting Started with C#**
Problem 1 β Self-introduction printer
- Project folder: `Homework01/`
- Key concepts: `Console.WriteLine`, string interpolation
Requirements
- Declare three variables: name, age, city
- Print in this format:
``` Hello! My name is OOO and I'm OO years old. I live in OO. ```
Expected output
Hello!
My name is Alex and I'm 25 years old.
I live in Seoul.Hints
- Declare variables like `string name = "Alex";`
- Use string interpolation like `$"My name is {name}..."`
Problem 2 β Greet with current time
- Project folder: `Homework02/`
- Key concepts: `DateTime.Now`, string interpolation
Requirements
- Read the user's name
- Print the current time alongside the greeting (using `DateTime.Now`)
Expected output
Name: Min
Hello, Min!
The current time is 2025-05-18 14:30:00.Hints
- Format time as `$"{DateTime.Now:yyyy-MM-dd HH:mm:ss}"`
- `Console.ReadLine()` returns `string?`
Check your answer
Try it yourself, then compare against the [`answer/`](./answer/) folder.
Answer (answer/)
homework/answer/Homework01/Homework01.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodingNow.Lecture.Basics01</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
homework/answer/Homework01/Program.cs
// Self-introduction printer
string name = "Alex";
int age = 25;
string city = "Seoul";
Console.WriteLine("Hello!");
Console.WriteLine($"My name is {name} and I'm {age} years old.");
Console.WriteLine($"I live in {city}.");
homework/answer/Homework02/Homework02.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>CodingNow.Lecture.Basics01</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
homework/answer/Homework02/Program.cs
// Greet with current time
Console.Write("Name: ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");
Console.WriteLine($"The current time is {DateTime.Now:yyyy-MM-dd HH:mm:ss}.");
Try It Yourself
cd src/HelloApp
dotnet run
cd ../Echo
dotnet run
cd ../MultiPrint
dotnet runNext Lecture
[02_Variables_and_Types](../02_%EB%B3%80%EC%88%98%EC%99%80_%ED%83%80%EC%9E%85/) β Learn the container for values: variables and types.
All lecture materials and example code are openly available on GitHub.
View on GitHub β