Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • Leaders
Posted

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] ...
}

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...