C# 单击按钮时,如何调用方法并传递参数?
我必须遵守这一守则:C# 单击按钮时,如何调用方法并传递参数?,c#,xamarin,C#,Xamarin,我必须遵守这一守则: correctButton.Clicked += (sender, e) => { App.DB.IncrementScore(AS.cfs, AS.phrase); correctAns++; AS.pointsCount[(int)AS.cfs]++; scoreCountLabel.Text = FontAwesome.FAStop
correctButton.Clicked += (sender, e) =>
{
App.DB.IncrementScore(AS.cfs, AS.phrase);
correctAns++;
AS.pointsCount[(int)AS.cfs]++;
scoreCountLabel.Text = FontAwesome.FAStop.Repeat(correctAns);
Device.StartTimer(TimeSpan.FromSeconds(0.5), () =>
{
switch (AS.cardOrder)
{
case CardOrder.FirstToLast:
AS.orderPhraseIndex++;
AS.phraseIndexList.Add(AS.orderPhraseIndex);
getPhraseFirstToLast();
break;
case CardOrder.Random:
getRandomNumber();
getRandomPhrase();
break;
}
return false;
});
};
我想将运行的代码移动到一个方法中,并传递参数。但是,当单击correctButton时,我如何调用该方法?使一个方法无效MyMethodobject sender,EventArgs e并附加它事件:correctButton.clicked+=MyMethod;读一读。
correctButton.Clicked += correctButtonClicked;
protected void correctButtonClicked(object sender, EventArgs e)
{
// code goes here
}