C# · Lesson 1 · On the house

Hello C#

Top-level statements, Console.WriteLine, dotnet new console, and dotnet run. Lesson 1 is free — on the house.

Lessons · C# · Lesson 1 of 10 · On the house

Hello C#

Top-level statements, Console.WriteLine, dotnet new console, and dotnet run.

Illustration for C#
Lesson 1 is on the house.

Create a project with dotnet new console -o Hello, then cd Hello and dotnet run. The SDK builds and runs Program.cs.

Modern C# allows top-level statements: the file can start directly with Console.WriteLine("hello"); with no class or Main method written by you.

Statements end with ;. Comments are // for a line and /* ... */ for blocks. C# is case-sensitive: console is not Console.

Console.Write prints without a newline; Console.WriteLine adds one. String interpolation inserts values: $"2 + 3 = {2 + 3}".

Misses: forgetting the semicolon, writing print(...), and lowercase console.writeline.

hello

// Program.cs
Console.WriteLine("hello");
Console.Write("no newline, ");
Console.WriteLine($"2 + 3 = {2 + 3}");
Match this when you type.

Quiz

Which command creates a console project?

Quiz

What do top-level statements remove?

Quiz

What does $"2 + 3 = {2 + 3}" produce?

Quiz

Is C# case-sensitive?

Check

Match the still for: Hello C#.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.