c#报错:无法将类型“void”隐式转换为“System.EventHandler”

代码:

//randDoc已经在其他地方定义
public async void GetDoc()
 {
  for (int i = 0; i < randDoc.GetArrayLength(); i++)
  {
     Button button = new Button { Text = randDoc[i].GetProperty("id").GetInt32().ToString()};
     button.Clicked += GoToDoc(randDoc[i].GetProperty("id").GetInt32()); //这行报错
     stack.Children.Add(button);
  }
}
public void GoToDoc(int id)
 {}

button.Clicked += GoToDoc(randDoc[i].GetProperty("id").GetInt32()); 这个代码是要给Clicked增加一个实现按钮点击的函数。所以你的GoToDoc(randDoc[i].GetProperty("id").GetInt32());这个方法要返回一个按钮点击函数的实现。而不是void类型的函数。

this.button.Click += new System.EventHandler(this.button_Click);