我不理解的方法参数出错

时间:2017-02-01 02:24:54

标签: c# methods arguments return-value

我正在高中上课,教授C#和.net框架,python等。我必须制作一个程序,使用返回方法对抗一个人使用“Rock,Paper,Scissors”这个单位的项目。

我在Microsoft Visual Studios 2015上遇到了一个错误 No Overload for method 'PCRandomizer' takes 1 arguments

我仍然对整个系统都很陌生,所以我很难理解这一点,但我的程序(到目前为止)是这样的;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rock__Paper__Scissors
{
    public partial class rockPaperScissors : Form
    {
        public rockPaperScissors()
        {
            InitializeComponent();
        }
    int playerChoice;

    // Variable to indicate what the choice is.
    int pcChoice;

    private int PCRandomizer()
    {


        // Create a Random Object.
        Random rand = new Random();

        // Get the rand integer between 1 and 3.
        // 1 and the PC has chosen Rock.
        // 2 and the PC has chosen Paper.
        // 3 and the PC has chosen scissors.
        pcChoice = rand.Next(1, 3);

        // This returns the value back to the main method.
        return pcChoice;
    }



    private void playerRockPic_Click(object sender, EventArgs e)
    {
        playerChoice = 1;

        PCRandomizer(out pcChoice);
    }

    private void playerPaperPic_Click(object sender, EventArgs e)
    {

    }

    private void playerScissorsPic_Click(object sender, EventArgs e)
    {

    }

    private void resetButton_Click(object sender, EventArgs e)
    {

    }

    private void exitButton_Click(object sender, EventArgs e)
    {
        // Close the Form
        this.Close();
    }
  }
}

我为长篇文章道歉,但我已经非常绝望,因为这已经落后于日程安排,我班上的几个人也有这个问题。

我找到了这个页面here,但我不明白。

1 个答案:

答案 0 :(得分:3)

因此,您只需将out变量设置为pcChoice的结果,而不是使用PCRandomizer。该方法返回整数,该整数将分配给pcChoice

private void playerRockPic_Click(object sender, EventArgs e)
{
    playerChoice = 1;

    pcChoice = PCRandomizer();
}