gpt4 book ai didi

c# - 无法分配给 'method',因为它是一个“方法组”

转载 作者:行者123 更新时间:2023-11-30 21:58:47 24 4
gpt4 key购买 nike

我无法运行我的代码,因为有一条错误提示:

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

这很奇怪,因为我使用了与我的其他方法相同的结构并且它们没有问题。这是我的代码。

 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

我的另一个窗口:

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);
}

最佳答案

你需要

frm.OnNewLand += NewLand;

代替

frm.OnNewLand += OnNewLand;

您可能有兴趣了解方法组的含义。访问this所以线程。

关于c# - 无法分配给 'method',因为它是一个“方法组”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29840120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com