是否可以将变量作为类的文件名传递给函数并获取或设置其值?

时间:2019-07-15 14:43:28

标签: c#

我需要将字符串作为类的字段名称传递给函数。获取或更新函数中类的值。有可能做得到吗?

//Try to describe the question as following code...
public class TEST {
  public string DATA1 { set; get; }
}
string param = "DATA1"; //DATA1 is one of the field of class TEST

private void GrabFieldData(string param) {
  string str = TEST.param;  //grab the value of TEST.DATA1
}

private void UpdateFieldData(string param) {
  string str = "new data";
  TEST.param = str;         //update the value of TEST.DATA1
}

0 个答案:

没有答案