Click here to Skip to main content
15,888,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
TextBox textBoxA = this.GetType().GetField("textBox1", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this) as TextBox;
textBoxA.Text = "test";
Posted
Updated 2-Oct-11 21:59pm
v3
Comments
Simon Bang Terkildsen 3-Oct-11 4:05am    
if you by variables mean fields then it does work, the textBox1 control you're getting is an auto generated field.
In short the posted code gets any non public fields of the class. But you might try to ask something different, but since the posted code isn't the code which troubles you it's hard to tell.

1 solution

Use GetField() as shown here[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900