我有这个数组:
Button[] RightArr = new Button[12] { button13, button14, button15, button16, button17, button18, button19, button20, button21, button22, button23, button24, };
我想检查是否有4个绿色背景颜色按钮以及是否有某些操作,例如:MessageBox.Show("There are 4 green buttons");
我该怎么做?
答案 0 :(得分:2)
您可以使用LINQ执行此操作。我假设,绿色按钮=背面颜色为绿色的按钮。随意改变它。
var greenbtns = (from m in RightArr where m.BackColor == Color.Green select m).ToList();
if (greenbtns.Count >= 4) {
MessageBox.Show("There are 4 green buttons");
}