From your variable naming, I suggest that the indexer would belong to
(plural, therefore an indexer makes sense), so we would get
this.chkbox1.Checked = lights.Value;
private void chkbox1_CheckedChanged(object sender, EventArgs e)
this.lights.Value = this.chkbox1.Checked;
But this leaves us with the problem that
is, as the error message seys, of type int
]. So we cannot assign it to Checked
], since that requires a value of type bool
Please improve your question using the "Improve question" link just beneath it to provide the type definition for
. That's no part of the .NET framework that I am aware of. Maybe it stems from the namespace
, that I don't know as well.
But from your code and comments, I think you want to assing individual bits of
to several checkboxes' Checked properties.
Try this one
int mask = 1 << 3;
int match = lights.Value & mask;
bool bitIsSet = match != 0;
this.chkbox3.Checked = bitIsSet;
this.chkbox3.Checked = ((lights.Value & (1 << 3)) != 0);
You cannot access individual bits directly in C#, you have to circumvent that with binary AND and OR operations. The above example prepares a bit mask for the third bit by left-shifting '00000001' three times to '00001000'.
This mask AND yourValue gives an integer that equals zero if the interesting bit was not set. It's the same as 'mask' if the bit was set. You can now use a comparison with zero to get the correct value for 'Checked'.
For correctly setting
's individual bits from their respective
values, you have to AND (&) and OR
] (|) things in the right order.