Evaluate string to command in C#?

ThienZ

Well-known member
Joined
Feb 10, 2005
Messages
45
Location
Germany
if i have a class that has attributes: attr01, attr02, ... attr16, and i want to check a same thing for each of these attributes it would be convenient if i can evaluate his string :
for(int i=1; i<=16; i++) {
if(eval["myClass.attr" + i] .....
}

i know System.Controls("...") from VBA hat evaluate strings to commands. Are there something like this in C# too?

thx in advance.
 
Well, it really sounds like you just want to reference the attributes as an array.
Evaluating strings as code really should only be used if you are trying to make a programming language.

Code:
bool attr[17];
for(int i = 1; i <= 16; i++) {
  if (attr[i] ...
}
:)
 
no iceplug,

i have a strongly typed dataset. this dataset has meanwhile 167 columns, some of them named with a string and numbers (like obj1, obj2, ... obj16).
Now i want to do something if mydataset.obj1 fill a certain term and i do this to obj2, obj3, ... obj16 too. the bad way to do this is to copy the code 16 times and number the attribute in each code 1..16.

i want to avoid this way of programming since im going to have this problem often...
 
Back
Top