Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

How to call a method by using method name

$
0
0

a simple winform application, I try the reflection, but info is always null. 

namespace WindowsFormsApplication18
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        void HelloWorld()
        {
            MessageBox.Show("Hello World!");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            MethodInfo info = this.GetType().GetMethod("HelloWorld");
           info.Invoke(this, null);       

        }
    }
}


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>