Eval function in C #

How can I evaluate a string in a C # Windows application because I need to dynamically select an object in a form based on a combination of 2 lines that give me the name of the object I need

+3
source share
4 answers

You can try ControlCollection.Find to find the control by name.
For instance:

MyForm.Controls.Find("FooButton", true);

The method returns an array of the control with the Name property set to "FooButton".

There is no C # equivalent . But from the link you can find useful answers. Ofc, if you want to find or evaluate something than winform controls

UPDATE: I think sometimes it is better to control the control directly. For instance:

Control control = this.Controls["FooTxtBox"];
if(control==null)
        {
            MessageBox.Show("Control not found");
        }
control.Text = "something";
+2

( ), .NET Framework 5.

, ?

0

Just use the string as a search for the collection Form.Controls. Then, when you have an instance of the control, just call any method you need to select it.

0
source

Source: https://habr.com/ru/post/1768381/


All Articles