C # convert string to component name and variable name,

Source: Internet
Author: User

C # convert string to component name and variable name,

String to component name

(Controls ["button1"] as Button ). text = "Hello"; // separate component (Controls ["tabControl1"]. controls [0]. controls ["performance1"] as TextBox ). text = "111.111.111.111"; // nested component

 

Variable name of a string

String str = "demo"; // you can write it to the following button#click. demo is the following variable name: public string demo = "Old String"; private void button#click (object sender, EventArgs e) {// obtain the variable value MessageBox through a string. show (this. getType (). getField (str ). getValue (this ). toString (); // display the Old String GetType (). getField (str ). setValue (this, "New String"); MessageBox. show (spp); // display New String MessageBox. show (this. getType (). getField (str ). getValue (this ). toString (); // display New String}


Or

Public string Demo = "Old String"; private void button2_Click (object sender, EventArgs e) {// get the variable value MessageBox through the string. show (this. getType (). getField ("Demo "). getValue (this ). toString (); // display the Old String // assign this to the variable. getType (). getField ("Demo "). setValue (this, "New String"); // The New Value MessageBox. show (Demo); // display New String MessageBox. show (this. getType (). getField ("Demo "). getValue (this ). toString (); // display New String}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.