Search code examples
c#unassigned-variable

What did I do wrong here? The only error I get is near the bottom. Use of unassigned local variable 'parts' right after "add tax"


 private decimal TaxCharges()
    {
        decimal addTax;
        decimal parts;

        addTax = parts * 0.06m;
        taxTxtBx.Text = addTax.ToString("c");
        return addTax;
    }

unassigned local variable 'parts' right after "addTax = parts


Solution

  • The variable parts has never been assigned a value.

    Assign it a value before making use of the variable. For example:

    decimal parts = 0;