通过字符串访问变量 [英] Accessing a variable via string

查看:123
本文介绍了通过字符串访问变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个字符串数组,其中包含大量字节变量的名称,我需要设置它们,并需要使用这些字符串访问它们.

我可以通过反射来访问控件,但不适用于变量

Hello,

I have a string array which has names of plenty byte variables, i need to set them and i need to access them with these strings.

I can access a control with reflection like that, but doesn''t work for variables

TextBox textBoxA = this.GetType().GetField("textBox1", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as TextBox;
textBoxA.Text = "test";

推荐答案

此处使用GetField() [

这篇关于通过字符串访问变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆