No there's no eval method unfortunately but you can use Reflection in most
cases to evaluate property expressions or call expressions on objects
dynamically.
eval(textbox + x).text = "item: " + x;
Here's one of the wrappers I use for this sort of thing:
public const BindingFlags MemberAccess =
BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance | BindingFlags.IgnoreCase ;
public static object GetField(object loObject,string lcProperty)
{
return
loObject.GetType().GetField(lcProperty,wwUtils.Mem berAccess).GetValue(loObje
ct);
}
public static void SetField(object loObject,string lcProperty,object
loValue)
{
loObject.GetType().GetField(lcProperty,wwUtils.Mem berAccess).SetValue(loObje
ct,loValue);
}
You can then call this like so:
(TextBox) tb = wwUtils.GetField(this,"textbox" + x);
string text = tb.Text;
This works as long as the the field or property in question is not marked as
Private as reflection requires external visibility in order to get at the
types. The same sort of thing works for Properties...
Hope this helps,
+++ Rick ---
--
Rick Strahl
West Wind Technologies
http://www.west-wind.com/ http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web
"Will" <ws*****@comcast.net> wrote in message
news:03****************************@phx.gbl...
in javascript or the like, when you wish to evaluate a
string you use eval() for instance if you had five text
boxes named textbox1, textbox2, etc. you would write
something like:
for (x=1;x<5;x++) {
eval(textbox + x).text = "item: " + x;
}
how can you do a similar thing in C#? I cannot believe
that there is no eval method. That would just be
rediculous. Thanks in advance for help! :)
Will