[問題] c#關於type的定義

看板C_Sharp (C#)作者 (just do it)時間18年前 (2007/08/13 14:14), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/2 (看更多)
小弟目前的程式如下: 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

08/13 15:30, , 1F
object x = a;if (x is int){... 像這樣嗎><
08/13 15:30, 1F
※ 編輯: scdog 來自: 140.96.194.99 (08/13 16:52)
文章代碼(AID): #16l_RDlh (C_Sharp)
討論串 (同標題文章)
文章代碼(AID): #16l_RDlh (C_Sharp)