What is the preferred syntax for coding a forms app with a checkbox that can be ticked (true) or not (false). As there exists also the indeterminate state.
A task in a course required bool to be sent to a overloaded method. This code works, but is it the best code? Asking as the course material is buggy.
A task in a course required bool to be sent to a overloaded method. This code works, but is it the best code? Asking as the course material is buggy.
C#:
private void _buttonSameMethod2ParamsDifferent_Click(object sender, EventArgs e)
{
if (_checkBoxFastAnstalld.CheckState == CheckState.Checked)
{
Personinfo(Convert.ToInt32(_textBoxAlder.Text), _checkBoxFastAnstalld.Checked);
}
else if (_checkBoxFastAnstalld.CheckState == CheckState.Indeterminate)
{
Personinfo(Convert.ToInt32(_textBoxAlder.Text), false);
}
else
{
Personinfo(Convert.ToInt32(_textBoxAlder.Text), _checkBoxFastAnstalld.Checked);
}
}
Last edited by a moderator: