我写了下面的类来返回一个随机数,比如掷骰子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GameTest
{
class Dice
{
public int publicMinNum
{
get { return _minNum; }
set { _minNum = value; }
}
public int publicMaxNum
{
get { return _maxNum; }
set { _maxNum = value; }
}
static int _minNum;
static int _maxNum;
static Random diceRoll = new Random();
public int rolled = diceRoll.Next(_minNum, _maxNum);
}
}
Run Code Online (Sandbox Code Playgroud)
这个类在我的表单中被称为几次:
private void btnPushMe_Click(object sender, EventArgs e)
{
Dice myRoll = new Dice(); …Run Code Online (Sandbox Code Playgroud)