← Back to C# series
🟣
Basics
Basics Β· Prerequisite: none

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.

C#.NET 8basicsgetting started
Duration
⏱ ~1-1.5 hours
Level
πŸ“Š Beginner
Prerequisite
🎯 None
OUTCOME
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.

bash
dotnet --version
# example output: 8.0.xxx

If 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

bash
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.

csharp
// 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

csharp
// Your first C# program
Console.WriteLine("Hello, C# !");

**Output**

text
Hello, C# !

**Note:** Don't forget the semicolon (`;`). C# delimits statements with `;`, not newlines.

Example 2 β€” `Echo/Program.cs`: take input and greet

csharp
Console.Write("Enter your name: ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");

**Output**

text
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

csharp
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**

text
=== 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

xml
<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

csharp
// Greet the user by name
Console.Write("Enter your name: ");
string? name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");

src/HelloApp/HelloApp.csproj

xml
<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

csharp
// Your first C# program
Console.WriteLine("Hello, C# !");

src/MultiPrint/MultiPrint.csproj

xml
<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

csharp
// 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

  1. Writing `Console.Writeline` with the wrong casing β€” C# is **case-sensitive**.
  2. Forgetting the trailing `;` β€” compile error.
  3. Writing `"{name}"` without the `$` β€” the literal `{name}` is printed.
  4. Running `dotnet run` outside the project folder and getting a "project not found" error.
  5. 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

text
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

text
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

xml
<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

csharp
// 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

xml
<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

csharp
// 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

bash
cd src/HelloApp
dotnet run

cd ../Echo
dotnet run

cd ../MultiPrint
dotnet run

Next 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.

Example code / lecture materials

All lecture materials and example code are openly available on GitHub.

View on GitHub β†—