如何将标签值更改为随机数?

时间:2016-10-12 01:31:29

标签: c# visual-c#-express-2010

随机数值应该打印到名为' number'的标签上。 - Visual C#

private void button1_Click(object sender, EventArgs e) 
{
        Random random = new Random();
        int randomNumber = random.Next(0, 100);
        number.Text = randomNumber();  
    }

2 个答案:

答案 0 :(得分:1)

只需分配值,不要像函数一样使用它

int randomNumber = random.Next(0, 100);
number.Text = randomNumber.ToString() ; 

答案 1 :(得分:-1)

Random random = new Random();
private void button1_Click(object sender, EventArgs e) 
{

    int randomNumber = random.Next(0, 100);
    number.Text = randomNumber();  
}