ThienZ Posted March 14, 2005 Posted March 14, 2005 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. Quote
Leaders Iceplug Posted March 14, 2005 Leaders Posted March 14, 2005 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. bool attr[17]; for(int i = 1; i <= 16; i++) { if (attr[i] ... } :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
ThienZ Posted March 14, 2005 Author Posted March 14, 2005 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 i'm going to have this problem often... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.