Zebra0.com

csharp boolean

Boolean Variables and Properties

If you have a Boolean variable or property, you do not need to compare it to anything to get a Boolean expression.
In this example, the checked property of a checkbox is used. A Boolean variable or property doesn't need to be compared to anything, it already has a value of true or false.

Example: This program has just one checkBox called chkRed.

 private void chkRed_CheckedChanged(object sender, EventArgs e)
        {
            if(chkRed.Checked)
            {
                this.Text = "Yes, red!";
                this.BackColor = Color.Red;
            }
            else
            {
                this.Text = "No, you hate red!";
                this.BackColor = Color.Silver;
            }
        } 

You do not need to say if(chkRed.Checked==true)...

Example: a variable declared as bool ready;

 if (ready) this.BackColor = Color.Green;

End of lesson, Next lesson: