Possible Duplicate:
C# – Is there a better alternative than this to 'switch on type'?
Hello suppose i get a big if/else on class type. it’s there a way to do it with a switch case ?
Example :
function test(object obj)
{
if(obj is WebControl)
{
}else if(obj is TextBox)
{
}
else if(obj is ComboBox)
{
}
etc …
I would like to create something like
switch(obj)
{
case is TextBox:
break;
case is ComboBox:
break;
}
}
Update C# 7
Yes: Source
Prior to C# 7
No.
http://blogs.msdn.com/b/peterhal/archive/2005/07/05/435760.aspx
Link: https://blogs.msdn.microsoft.com/peterhal/2005/07/05/many-questions-switch-on-type/