Al

Al

  • NA
  • 30
  • 6.2k

replacing if with swtich

Apr 27 2020 8:44 AM

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)