error CS0165: Use of unassigned local variable 'discount' means you read a local variable on a path where nothing has been stored in it yet. Give it a starting value where you declare it (int discount = 0;), or assign it in every branch before the line that reads it.

Fields of a class start at zero or null automatically; local variables inside a method do not. C# refuses to let you read one until it can see an assignment on every path that leads to the read.

The error

...\Program.cs(9,32): error CS0165: Use of unassigned local variable 'discount' [...\FixLab.csproj]
Build FAILED.

The folder part of both paths was shortened to ...; nothing else was changed.

Why it happens

int points = 120;
int discount;

if (points > 100)
{
    discount = 10;
}

Console.WriteLine($"Discount: {discount}%");

discount is declared without a value and assigned only inside the if. When points is 100 or less, the program would reach line 9 with nothing in the variable. The compiler's definite-assignment check does not track the value stored in a variable; it sees a path where discount is never assigned, and reports the read at line 9, column 32. Constants are different: with const int points = 120; the same program built and printed Discount: 10%, because a constant condition is evaluated at compile time.

This is a protection, not a nuisance. Without it, a forgotten assignment would show up later as a wrong number at run time; C# moves that bug to compile time.

The fix

int points = 120;
int discount = 0;

if (points > 100)
{
    discount = 10;
}

Console.WriteLine($"Discount: {discount}%");

With a starting value of 0, every path has an assignment. The project built with warnings treated as errors and printed Discount: 10%. Choose the starting value on purpose: it is the answer for the case your if does not handle, so it should be the correct "no discount" value, not just any number that makes the error go away.

The alternative is an else branch that assigns the other value, which keeps the two cases side by side, so a reader sees both answers in one place.

How it was reproduced

A dotnet new console project on .NET SDK 10.0.403 (net10.0, nullable and implicit usings on, no packages) with the program above. dotnet build --no-incremental failed with the single CS0165 error; the fixed version passed dotnet build --no-incremental -p:TreatWarningsAsErrors=true and dotnet run printed the discount.

Frequently asked

How do I fix use of unassigned local variable in C#?
Give the variable a value where you declare it, such as int total = 0;, or assign it in every branch (if and else) before the line that reads it.
Why do local variables not get a default value in C#?
C# requires a local variable to be definitely assigned before it is read, so a forgotten assignment is caught at compile time instead of producing a silent wrong value. Class fields, by contrast, start at their default value.
Why does the compiler not see that my if is always true?
Because points is a variable, the compiler does not use its value: the if has a path where it is false, and on that path discount has no value. With const int points = 120; the same code built without the error.

More decoded compiler errors are in the Fixes category.