根据函数名动态调用

来源:互联网 发布:js 清空div 中的元素 编辑:程序博客网 时间:2024/05/17 23:29

 

 

private void button1_Click(object sender, System.EventArgs e)

         {

              object[] methodArgs = {"test",10.2};

              try

              {

                   object s = typeof(MainForm).InvokeMember("test",BindingFlags.InvokeMethod,null,new MainForm(),methodArgs);

                   MessageBox.Show(s.ToString());

              }

              catch(Exception ex)

              {

                   MessageBox.Show(ex.Message);

              }

         }

         public string test(string a,double b)

         {

              return a+"double:"+b.ToString();

         }

         public string test(string a,int b)

         {

              return a+"int:"+b.ToString();

         }

         public string test(string a,int b)

         {

              return a+"int:"+b.ToString();

         }

原创粉丝点击