Q: Converting CheckBox.Checked to an int?

  • Thread starter Thread starter Visual Systems AB \(Martin Arvidsson\)
  • Start date Start date
V

Visual Systems AB \(Martin Arvidsson\)

Hi!

How do I convert a CheckBox.Checked to an int?

Regards

Martin Arvidsson
 
Hi Martin,

To get an int value out of you can do something like

int i = CheckBox.Checked ? 1 : 0;

A boolean value can't be translated to any other value, so you will need
to test it, if true use 1, otherwise use 0.
 
No, you shouldn't have to test it. You should be able to cast it into an
integer and get back 0 or 1 directly.
 
No, you shouldn't have to test it. You should be able to cast it into an
integer and get back 0 or 1 directly.

To add to this, there is no CType in C#, but you get the same effect using
Convert.ToInt32(bool)
 
Back
Top