5
Answers

Using a string to reference an object.

dtmoore

dtmoore

19y
2.6k
1
I am fairly new to C# and have been banging my head on my desk for a couple hours trying to figure this out, I am almost to the point where I think it cannot be done. Here is the problem. I have a series of textfields named in a sequential manner as follows: ex_1_1 ex_1_2 etc... I need to do a fairly large amount of math with these boxes and as the matrix of them spans quite a ways in both dimensions i really don't want to have to hardcode each reference (which is the reason for the naming) I planned on running a for loop and pulling the data out that way. I am getting an error when I try to do this. here is the code I am using for(int i=1; i<7; i++) { tempValue += ("em_1_" + i).Value } now this obviusly blows up because ("em_1_" + i) is a string not an object reference, but what I need is a way to make it reference my textfield. I have done this same thing in several other languages but cannot get it to work. Any help you could give me would be greatly appreciaited. thanks ~David
Answers (5)