.

.

.

.

如果使用string变量中的字符串作为另一个变量的名字,需要通过反射取得字符串对象,可以通过如下方式实现:

View Code
1 BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static;
2 Type type = this.GetType();
3 FieldInfo fi = type.GetField("变量名的字符串", bf);
4 string sql = fi.GetValue(this).ToString();

 

也可以写成另外一种形式:

View Code
1 BindingFlags bf = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Static;
2 string sql = this.GetType().GetField("变量名的字符串", bf).GetValue(this).ToString();



相关文章:

  • 2022-02-12
  • 2022-12-23
  • 2021-09-07
  • 2021-10-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-10-23
  • 2021-05-26
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案