Button incrementing from 0 to 9 and repeating I have to create a button which counts from 0 to 9, and after 9 come 0 again. One of my friends said that this code is not good enough. Can you explain to me why it's a problem to use -1?

int szám = 0;
private void counterButton_Click(object sender, EventArgs e)
{
    szám++;
    this.Text = szám.ToString();
    if (szám == 9)
    {
        szám = -1;
    }
}
Your code is ok. But there are always other ways to get the same result which may be more elegant.

private void counterButton_Click(object sender, EventArgs e)
{
    szám=(szám +1) % 10;
    this.Text = szám.ToString();
}


or you can do:

private void counterButton_Click(object sender, EventArgs e)
{
    szám=(9==szám)?0:szám+1;
    this.Text = szám.ToString();
}