Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单击按钮时,如何调用方法并传递参数?_C#_Xamarin - Fatal编程技术网

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
}