Sharon,
You would have to use reflection. First, you get the type for your
class. If the type is referenced, then you can do this:
// Get the Type.
Type type = typeof(<containing class>);
Or, you can just call GetType on yourself (or any other object
reference):
// Get the type.
Type type = this.GetType();
Then, you get the name of the field that you want:
// Get the field information.
FieldInfo fieldInfo = type.GetField("button" + i.ToString());
Finally, to get the field, you would call GetValue, passing the instance
of the object you want to get the field for:
// Get the value. The value has to be cast to a Button, since GetValue
returns an object.
Button currentButton = (Button) fieldInfo.GetValue(this);
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)
Sharon said:
Hi to all.
How do i reference a class member dynamically?
Somthing like:
byte i = 35;
Button currentButton = this["button" + i.ToString()];
Thanks,
Sharon.