private void checkBox1_CheckedChanged(object sender, EventArgs e) { if(checked) { farmer = new Farmer(1, 400); } else { farmer = new Farmer(1, 300); } } Help
what am I doing wrong
error after (checked)
screenshots
private void checkBox1_CheckedChanged(object sender, EventArgs e) { if(checked) { farmer = new Farmer(1, 400); } else { farmer = new Farmer(1, 300); } } Help
what am I doing wrong
error after (checked)
screenshots
The IDE says that the error is for two reasons:
checked is a keyword that is used to explicitly enable overflow checking when performing arithmetic operations and conversions with integer data. see the documentation . Therefore, it is already impossible to use it in if and there will be an error.Checkbox has a Checked property. I note that the property is written with a capital letter.
That it must be checked. Naturally, it is necessary to specify an object at the beginning, and then a property of the object through a dot. You now have it if it were not a keyword, then it does not apply to anything. And you need to write at least checkBox1.Checked
Because Does a property change this particular object? then you can cast the object that sent the event and check Checked with it, i.e.
if (((CheckBox)sender).Checked) { ... Source: https://ru.stackoverflow.com/questions/572598/
All Articles
if (checkBox1.Checked)for checked does not apply to anything - Alexey Shimansky