柔城 发表于 2013-1-2 22:47:20

使用泛型集合模拟双色球开奖C#代码

使用泛型集合模拟双色球开奖C#代码

<div class="postText"><div id="cnblogs_post_body">
新建一个 windows窗体应用程序 项目,在窗体上加一个TextBox控件(textBox1)和一个Button控件(button1),双击Button控件,在button1的点击事件的方法加入代码,如下,启动程序,点击按钮就可以看到随机生成的双色球号码。

<div class="cnblogs_code">private void button1_Click(object sender, EventArgs e)      {            textBox1.Text = "";            //生成红色球号码            List<int> _list;            _list = new List<int>(33);            for (int i = 1; i <34; i++)            {                _list.Add(i);            }            Random rd = new Random();            int index;            for (int i = 1; i < 7; i++)            {                index = rd.Next(_list.Count);                textBox1.Text = textBox1.Text + _list.ToString();                if (i < 6)                  textBox1.Text = textBox1.Text + ", ";                _list.RemoveAt(index);            }            //生成蓝色球号码            Random rb = new Random();            textBox1.Text = textBox1.Text + " + " + (rb.Next(16)+1).ToString();                  }
页: [1]
查看完整版本: 使用泛型集合模拟双色球开奖C#代码