作者scdog (just do it)
看板C_Sharp
标题[问题] c#关於type的定义
时间Mon Aug 13 14:14:36 2007
小弟目前的程式如下:
object Component;
public void setVisable(bool isVisable)
{
switch (Component.GetType().Name)
{
case "int":
((TextBox)Component).Visible = isVisable;
break;
case "string":
((TextBox)Component).Visible = isVisable;
break;
case "bool":
((CheckBox)Component).Visiable = isVisable;
break;
case "option":
break;
default:
break;
}
}
上面程式我觉得太过繁杂,不知有无更方便的作法
如
Type componentType = Component.getType();
((componentType)Component).Visable = isVisable;
谢拉!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.96.194.99
1F:→ juriolegend:object x = a;if (x is int){... 像这样吗>< 08/13 15:30
※ 编辑: scdog 来自: 140.96.194.99 (08/13 16:52)