3
Answers

replacing if with swtich

Al

Al

4y
507
1

hi

how can I replace if with swtich .  

protected void testSwitch( object myObject)
{
if (myObject.GetType() == typeof(Button))
{
Button btnMyObj = (Button)myObject;
btnMyObj.Visible = true;
}

switch (myObject)
{
case myObject.GetType() == typeof(Button):

//...
break;

default:
//...
break;
}

}

Answers (3)