C# Tutorial · C# Basics · Lesson 3 of 22

C# Syntax and Output

Statements, blocks, comments, Console.WriteLine and string interpolation.

Syntax basics

  • Statements end with ;, blocks use { }.
  • C# is case-sensitive: Console ≠ console.
  • Comments: // single line, /* ... */ multi-line, /// XML documentation.
  • Naming: PascalCase for types, methods and properties; camelCase for local variables and parameters.

Output

Console.WriteLine prints a line; Console.Write doesn't add a newline. String interpolation with $"..." embeds expressions, and format specifiers follow a colon:

Example 1
// Print a receipt
string item = "Coffee";
int qty = 2;
decimal price = 3.5m;
Console.Write("Order: ");
Console.WriteLine($"{qty} x {item}");
Console.WriteLine($"Total: {qty * price:C2}".Replace("¤", "$"));
Console.WriteLine($"{1234567.891:N2} | {0.256:P1} | {42,6}| {42,-6}|");
Console.WriteLine($"Today is {new DateTime(2026, 10, 12):yyyy-MM-dd}");

Output

Order: 2 x Coffee
Total: $7.00
1,234,567.89 | 25.6% |     42| 42    |
Today is 2026-10-12

Run this on your computer — see “Get Started” for setup.

Test yourself

Which prefix turns a string into an interpolated string?

  1. @
  2. $
  3. #
  4. %
Show answer

Answer: $