By the way, the equivalent of the iif() from VFP would be like this:
TitleLabel.Visible = TitleCheckBox.Checked ? true : false
? : is a basic operator - a triadic one.
In this particular case, since we already have a value of type bool, the direct assignment (as shown in another reply in this thread) is simpler, of course.
Also, the keyword
This is not required in many cases, although it can help with Intellisense.
Doesn't the compiler complain if you use "=" instead of "==" in the if()?
>I am new to C#, off and on for a couple years.
>
>I am trying to make a label visible by using a check box, but I cannot seem to figure out how to code it.
>
>Here's my code, but it doesn't work:
>
>
> private void titleCheckBox_CheckedChanged(object sender, EventArgs e)
> {
> if (this.titleCheckBox.Checked = true)
> {
> this.titleLabel.Visible = true;
> }
> else
> {
> this.titleLabel.Visible = false;
> }
>
> }
>
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)