这段代码是很多if/else
,我想知道它是否可以简化为少数几行。代码工作得很好,但我更喜欢有更高效和更清洁的方式。这段代码可以简化吗?
if (textBox_naam.Text.Length < 3)
{
textBox_naam.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_naam.BackColor = Color.White;
}
if (textBox_email.Text.Length < 5)
{
textBox_email.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_email.BackColor = Color.White;
}
if (textBox_body.Text.Length < 20)
{
textBox_body.BackColor = Color.FromArgb(205, 92, 92);
}
else
{
textBox_body.BackColor = Color.White;
}
我们有一个代码审查工作代码的姊妹网站。 – 2012-04-26 21:59:39
只是为了澄清,它似乎是指代码中的不同TextBox的?我几乎要将分支报表合并成一个if ... else if ...但我认为@达人的答案有帮助吗? – Eniola 2015-12-02 21:53:03