繁体   English   中英

我不明白的方法参数错误

[英]Error with method arguments that I don't understand

我目前正在我的高中上一堂课,讲授C#和.net框架,python等。我必须制作一个程序,该程序使用返回方法作为针对某人的对象,对他们播放“ Rock,Paper,剪刀”这个单位。

我一直在Microsoft Visual Studios 2015上遇到错误,说方法'PCRandomizer'的No Overload接受1个参数

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

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

我为冗长的帖子表示歉意,但我感到非常绝望,因为这已经比原定计划落后了一天,班上的几个人也遇到了这个问题。

我在这里找到此页面,但我不理解。

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

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

    pcChoice = PCRandomizer();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM