【发布时间】:2013-03-12 22:21:44
【问题描述】:
如何在c#中实现这个方法:
public static void SetParam(string element, string property, dynamic value){
// Do something
}
// Usage:
setParam("textBox1","Text","Hello");
在 JavaScript 中是这样的:
function SetParam(element, property, value) {
document.getElementById(element)[property]=value;
}
// Usage:
SetParam("textBox","value","Hello");
【问题讨论】:
-
C#代码中的“元素”是什么意思?
-
如果您在将值传递给单独的方法时知道元素和属性,为什么不能在代码隐藏中使用
textbox1.Text = value;而不是调用单独的方法来设置值。 -
我需要使用三个已知字符串从方法中设置属性值:元素(ElementID,例如 texbox1)、属性(例如 Text)和值。
标签: c# properties parameters get