المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Repeated code with little difference



C# Programming
05-22-2009, 02:25 AM
I'm wondering, how would I go about doing this in a much easier and logical manner? I have a lot of checkBox's being used and each one needs this exactly type of coding, just each one consecutively needs to have their object number +1 as shown below.

object cb1 = checkBox1.Tag;
object cb2 = checkBox2.Tag;
object cb3 = checkBox3.Tag;
if (checkBox2.Checked == true)
{
cb2 = "1";
}
else
{
cb2 = "0";
}

if (checkBox3.Checked == true)
{
cb3 = "1";
}
else
{
cb3 = "0";
}

if (checkBox1.Checked == true)
{
cb1 = "1";
}
else
{
cb1 = "0";
}

Help would be greatly appreciated!