Cannot assign to 'click' because it is a 'method group'

时间:2015-10-30 22:49:30

标签: c# events

I'm using linux monodevelop to do c# stuff , what is wrong with this ?

?

using System;
using Gtk;

namespace aaadd
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Application.Init ();
            MainWindow win = new MainWindow ();
            Button button = new Button();

            button.Click += new EventHandler (button_Click);
            win.Add (button);
            button.Show ();
            win.Show ();

            Application.Run ();
        }
        public static void button_Click(object sender, System.EventArgs e) 
        {

        }

    }
}

Error :

Cannot assign to 'click' because it is a 'method group'

1 个答案:

答案 0 :(得分:2)

To subscribe to the event you need to use

button.Clicked += new EventHandler (button_Click);