C# Practice Exercises

Invoice and Numeric Formatting

Format aligned currency output with interpolation.

Introduction

C# composite formatting makes console reports readable without manual padding.

Alignment components set field widths and the C format specifier uses the current culture's currency format.

Runnable C# example

C#
Run code →
Program.cs
using System;
class Program
{
    static void Main()
    {
        var lines = new[] { ("Book", 2, 12.50m), ("Pen", 3, 1.25m) };
        foreach (var (name, quantity, price) in lines)
            Console.WriteLine($"{name,-8} {quantity,2} {quantity * price,8:F2}");
    }
}
Result of running the code
Book      2    25.00
Pen       3     3.75

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges