假如我在主程序中获得了一个字符串,内容为"aa"
 而且主程序中也有void aa()这个方法,我如何根据这个字符串来调用该方法?  也就是如果字符串是"bb"的话那么就调用bb()这个方法

解决方案 »

  1.   

    if(str=="aa")
    {
     void aa();
    }
    if(str=="bb")
    {
    void bb();
    }
      

  2.   


    namespace WindowsApplication12
    {
        public partial class Form1 : Form
        {
            public void aa()
            {
                MessageBox.Show("in aa");
            }        public Form1()
            {
                InitializeComponent();            this.GetType().GetMethod("aa").Invoke(this, null);
            }
        }
    }
      

  3.   

    出问题了,我按照上面的代码运行的时候出现了异常
    未将对象引用设置到对象的实例。
    下面是我的代码,请楼上两位大侠帮我分析一下哪里不对using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                this.GetType().GetMethod("aaw").Invoke(this, null);
            }        private void Form1_Load(object sender, EventArgs e)
            {
                
            }        void aaw()
            {
                MessageBox.Show("ww");
            }
        }
    }