简体   繁体   中英

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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