看板 C_Sharp 關於我們 聯絡資訊
小弟目前的程式如下: 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
juriolegend:object x = a;if (x is int){... 像這樣嗎>< 08/13 15:30
※ 編輯: scdog 來自: 140.96.194.99 (08/13 16:52)