简体   繁体   English

无法分配给'方法',因为它是'方法组

[英]Cannot assign to 'method' because it is a 'method group

I can't run my code because there is a error saying: 我无法运行我的代码,因为有一个错误说:

Cannot assign to 'OnNewLand' because it is a 'method group 无法分配给'OnNewLand',因为它是'方法组

This is strange because I have used the same structure as my other methods and there were no problem with them. 这很奇怪,因为我使用了与我的其他方法相同的结构,并且它们没有问题。 Here is my code. 这是我的代码。

 private void CreateNewFlight()
        {
            string flightCode = ReadFlightCode();

            //Create the new bidder
            if (!string.IsNullOrEmpty(flightCode))
            {
                FlightWindow frm = new FlightWindow(Flightcode.Text);
                frm.Show();

                //Subscribe to the publisher's new bid and quit bid events
                frm.NewStart += OnNewStartClick;
                frm.NewChangeRoute += OnNewChangeRoute;
                frm.OnNewLand += OnNewLand; <----Here is the error <-------
            }
        }

Cannot assign to 'OnNewLand' because it is a 'method group 无法分配给'OnNewLand',因为它是'方法组

My other window: 我的另一个窗口:

public event EventHandler<Start> NewStart;
        public event EventHandler<ChangeRoute> NewChangeRoute;
        public event EventHandler<Land> NewLand;
private void btnStart_Click(object sender, RoutedEventArgs e)
        {

            Start startinfo = new Start(this.Title);
            OnNewStart(startinfo);   //Raise event   
            btnLand.IsEnabled = true;
            Routetxt.IsEnabled = true;
            changebtn.IsEnabled = true;
            btnStart.IsEnabled = false;
        }
        private void changebtn_Click(object sender, RoutedEventArgs e)
        {
            ChangeRoute changeinfo = new ChangeRoute(this.Title, Routetxt.Text);
            OnNewChangeRoute(changeinfo);   //Raise event   
        }
        private void btnLand_Click(object sender, RoutedEventArgs e)
        {
            Land landinfo = new Land(this.Title);
            OnNewLand(landinfo); //Raise event  
        }
        //Raise Event
        public void OnNewStart(Start e)
        {
            if (NewStart != null)
                NewStart(this, e);
        }

        public void OnNewChangeRoute(ChangeRoute e)
        {
            if (NewChangeRoute != null)
                NewChangeRoute(this, e);
        }

        public void OnNewLand(Land e)
        {
            if (NewLand != null)
                NewLand(this, e);
        }

You need 你需要

frm.OnNewLand += NewLand;

instead of 代替

frm.OnNewLand += OnNewLand;

You might be interested to know what does it mean by method group. 您可能有兴趣知道方法组的含义。 Visit this so thread. 访问这个线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM