C# if/else first statement working, the rest are not

前端 未结 3 518
梦如初夏
梦如初夏 2021-01-29 05:58

I know this is probably very basic, and I googled it and have gone through the search, but I\'m having an issue which a very basic if/else scenario. The first statement produce

3条回答
  •  忘掉有多难
    2021-01-29 06:12

    This is how C# read your code.

    if (season == 1)
        if (job == 1)
            label3.Text = "There is a 20% discount on the exterior job";
        else if (season == 2)
            if (job == 1)
                label3.Text = "There is a 20% discount on the exterior job";
            else if (season == 3)
                if (job == 2)
                    label3.Text = "There is a 30% discount on the interior job";
                else
                    label3.Text = "No discount, regular prices apply";
    

    C# does not consume your indents for its logic. So better use brackets.

提交回复
热议问题