在C#中的随机数

在C#中的随机数

本文介绍了在C#中的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到下面当我尝试运行我敢肯定它的一些简单的应用程序中的错误,但我没有看到它。我所试图做的,当我点击一个按钮,我已经标记播放。我想打电话给一个叫randomnumber方法。然后我想在lblPickFive_1要显示的结果。
我有2×2,Pick5和强力球。每一个随机数是要显示在自己的标签,我创建。



现在我只是希望得到过去,它显示在产生一个随机数并具有一一个标签,然后,我会移动到其他地方。我相信张贴更多的问题,如果我无法弄清楚休息。



错误1无过载方法'RandomNumber'取'0'参数

 使用系统;使用System.Windows.Forms的
;

命名空间LotteryTickets
{
公共部分Form1类:表格
{
///<总结>
///无参数的构造函数
///< /总结>
公共Form1中()
{
的InitializeComponent();

}


#地区==控件事件处理==
私人无效Form1_Load的(对象发件人,EventArgs五)
{
ClearWinningNumbers();
}


#endregion==结束控件事件处理==


#地区== ==方法 ;
///<总结>
///清除中奖号码球
///<内的文本; /总结>
私人无效ClearWinningNumbers()
{
this.lblPickFive_1.Text =;
this.lblPickFive_2.Text =;
this.lblPickFive_3.Text =;
this.lblPickFive_4.Text =;
this.lblPickFive_5.Text =;

this.lblTwoByTwo_1.Text =;
this.lblTwoByTwo_2.Text =;

this.lblPowerball_1.Text =;
this.lblPowerball_2.Text =;
this.lblPowerball_3.Text =;
this.lblPowerball_4.Text =;
this.lblPowerball_5.Text =;

this.lblPowerball_PB.Text =;
}
#endregion== End方法==;

私人无效cblTwoByTwo_2_SelectedIndexChanged(对象发件人,EventArgs五)
{

}

私人无效cblTwoByTwo_1_SelectedIndexChanged(对象发件人,EventArgs的发送)
{

}

私人无效btnPlay_Click(对象发件人,EventArgs五)
{
RandomNumber();

}

私人无效lblPickFive_1_Click(对象发件人,EventArgs五)
{

}
私人无效RandomNumber(INT分,INT最大值)
{
INT NUM =新的随机()和Next(最小值,最大值)。
lblPickFive_1.Text = num.ToString();
}
}
}


解决方案

您需要的值传递:

 私人无效btnPlay_Click(对象发件人,EventArgs五)
{
RandomNumber();

}



应该是:



 私人无效btnPlay_Click(对象发件人,EventArgs五)
{
RandomNumber(0,50000);

}


I get the error below when I try to run the application I am sure its something simple but I dont see it. What I am trying to do it when I click a button I have labeled Play. I want to call a method called randomnumber. Then I want the results to be displayed in lblPickFive_1.I have 2x2,Pick5,and powerball. Each random number is to be displayed in its own label I created.

For now I am just looking to get past the one of generating a random number and having it displayed in the one label then I will move onto the rest. And I am sure post more questions if I cant figure out the rest.

Error 1 No overload for method 'RandomNumber' takes '0' arguments

using System;
using System.Windows.Forms;

namespace LotteryTickets
{
public partial class Form1 : Form
{
    /// <summary>
    /// no-args Constructor
    /// </summary>
    public Form1()
    {
        InitializeComponent();

    }


    #region "== Control Event Handlers =="
    private void Form1_Load(object sender, EventArgs e)
    {
        ClearWinningNumbers();
    }


    #endregion "== End Control Event Handlers =="


    #region "== Methods ==";
    /// <summary>
    /// Clears the text inside the winning number "balls"
    /// </summary>
    private void ClearWinningNumbers()
    {
        this.lblPickFive_1.Text = "";
        this.lblPickFive_2.Text = "";
        this.lblPickFive_3.Text = "";
        this.lblPickFive_4.Text = "";
        this.lblPickFive_5.Text = "";

        this.lblTwoByTwo_1.Text = "";
        this.lblTwoByTwo_2.Text = "";

        this.lblPowerball_1.Text = "";
        this.lblPowerball_2.Text = "";
        this.lblPowerball_3.Text = "";
        this.lblPowerball_4.Text = "";
        this.lblPowerball_5.Text = "";

        this.lblPowerball_PB.Text = "";
    }
    #endregion "== End Methods ==";

    private void cblTwoByTwo_2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    private void cblTwoByTwo_1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    private void btnPlay_Click(object sender, EventArgs e)
    {
        RandomNumber();

    }

    private void lblPickFive_1_Click(object sender, EventArgs e)
    {

    }
    private void RandomNumber(int min, int max)
    {
        int num = new Random().Next(min, max);
        lblPickFive_1.Text = num.ToString();
    }
    }
}
解决方案

You need to pass in values:

private void btnPlay_Click(object sender, EventArgs e)
{
    RandomNumber();

}

should be:

private void btnPlay_Click(object sender, EventArgs e)
{
    RandomNumber(0, 50000);

}

这篇关于在C#中的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:53