Yesterday, my colleagues wrote a reflected code with VB.Net 2002. How did I get a member variable at runtime! I have seen it, I feel that the code should be no problem, use C # (vs.net 2003) to rewrite, and the result is successful. Attached C # code as follows:
Public class form1: system.windows.forms.form {private system.windows.Forms.Button Button1;
Public Form1 () {// Windows Form Designer Support for INITIALIZEComponent ();
Private void initializecomponent () {this.button1 = new system.windows.Forms.Button ();
// set profment value ...}
. Private void Form1_Click (object sender, System.EventArgs e) {System.Reflection.FieldInfo field = this.GetType () GetField ( "button1", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); System .Windows.forms.control ctl = (control) Field.getValue (this); MessageBox.show (CTL.Text System.Environment.Newline CTL.Name);}}
So why can I get "Button1" System.Reflection.fieldInfo object in VB.NET is never obtained in VB.NET? Use this.gettype (). Getfields () [VB.NET is me.gettype (). GetFields ()] enumerate all member fields, and found that the name original "Button1" has become "_button1"! ! ! How can I get a prefix underline? ? ? ! ! ! Is it a vb.net compiler? ! Hey, after the "Button1" in the first line of Form1_Click event is changed to "_Button1", success!