哈喽,你好啊,我是雷工!
接着练习选号器的设计与实现,以下为练习笔记;
01 添加类同样的方式添加类,命名为Selector;
然后将其拖入到【LeiGongModels】文件夹中;
02 选号器类编写在选号器类中创建相关的属性和方法;
代码如下:
namespace LeiGongSuperLotto{/// <summary>/// 选号器类/// </summary>internal Selector {//红色、蓝色球池(用于随机选号)public List<string> RedBallList { get; set; }public List<string> BlueBallList { get; set; }//存储选中的号码public List<SuperLotoData> SelectedBalls { get; set; } = new List<SuperLotoData>();private Random random = new Random();/// <summary>/// 构造方法/// </summary>public Selector() { RedBallList = new List<string> {"01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35" }; BlueBallList = new List<string> {"01","02","03","04","05","06","07","08","09","10","11","12" }; }#region 生成不同数量的红蓝色球方法public List<string>CreateRedNum(int count) { List<string> numList = new List<string>();while(true) {if (numList.Count == count) break;//如果集合数量达到随机数个数,则退出循环string num = RedBallList[random.Next(35)];if (numList.Contains(num)) continueelse { numList.Add(num); } }return numList; }public List<string> CreateBlueNum(int count) { List<string> numList = new List<string>();while (true) {if (numList.Count == count) break;//如果集合数量达到随机数个数,则退出循环string num = BlueBallList[random.Next(12)];if (numList.Contains(num)) continue;else { numList.Add(num); } }return numList; }#endregion }}03 后记以上为选号器类的编写,接下来将会练习在UI中使用选号器对象完成选号功能,
上述有记录不当之处欢迎留言指出,更多相关话题也可以在交流群内探讨;