小编Chr*_*ris的帖子

理解类并使用Random

我写了下面的类来返回一个随机数,比如掷骰子:

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)

c# class

-1
推荐指数
2
解决办法
375
查看次数

标签 统计

c# ×1

class ×1