您的位置:首页 > 其它

sed的常用命令总结(一)

2012-06-19 18:31 267 查看

C# 字符串转为变量名,通过字符串给变量赋值

例子一、将字符串转为变量名

string str = "spp";

public string spp = "very good";

private void button1_Click(object sender, EventArgs e)

{

MessageBox.Show(this.GetType().GetField(str).GetValue(this).ToString());

}

例子二、通过字符串给变量赋值

public string gisoracle = "ok";

private void button2_Click(object sender, EventArgs e)

{

//通过字符串获得变量值

MessageBox.Show(this.GetType().GetField("gisoracle").GetValue(this).ToString());

//通过给变量赋值

this.GetType().GetField("gisoracle").SetValue(this, "gisoracle@126.com");

//新的值

MessageBox.Show(this.GetType().GetField("gisoracle").GetValue(this).ToString());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: