c# - How do I merge all the cases into One? -
private void makemolevisable(int mole, picturebox molehill) { switch (mole) { case 1: if (p01.image == pmiss.image && molehill.image == phill.image) { molesmissed ++; } p01.image = molehill.image; break; case 2: if (p02.image == pmiss.image && molehill.image == phill.image) { molesmissed++; } p02.image = molehill.image; break; ** have 36 of these case statements each 1 different picture box; how group them 1 case statement code can more efficient**
try this:
string controlidsuffix = mole < 10 ? "0" : "" + mole.tostring(); control[] picboxes = this.controls.find("p" + controlidsuffix, true); if (picboxes.length > 0) { picturebox p = picboxes[0] picturebox; if (p != null) { if (p.image == pmiss.image && molehill.image == phill.image) molesmissed++; p.image = molehill.image; } }
Comments
Post a Comment