RT,我的代码如下,
ImageList imglst = new ImageList();
 List<PictureBox> pictureboxes = new List<PictureBox>();
 List<int> indexes = new List<int>();
 Random r = new Random(DateTime.Now.Millisecond);
 for (int i = 0; i < 9; i++)
 {
     indexes.Insert(r.Next(0, indexes.Count - 1), i);
    //Thread.Sleep(10);
 }
 foreach (var item in indexes)
 {
    pictureboxes[item].Image = imglst.Images[item];
 }
报错是这一句:indexes.Insert(r.Next(0, indexes.Count - 1), i);
报错内容:“minValue”不能大于 maxValue。”麻烦各位大哥大姐帮忙看看,我是新手,不怎么懂,如果各位有更好地实现方法,也可以教教我啊,谢谢了

解决方案 »

  1.   

    //装载19个图片的ImageList
                ImageList imglst = new ImageList();
                //准备装载19个图片的PictureBox,建议使用List<T>
                List<PictureBox> pictureboxes = new List<PictureBox>();             //产生随机索引顺序
                List<int> indexes = new List<int>();
                Random r = new Random(DateTime.Now.Millisecond);            for (int i = 0; i < 19; i++)
                {
                    indexes.Insert(r.Next(0, indexes.Count - 1), i);
                    Thread.Sleep(10);
                }             //装载图片
                foreach (var item in indexes)
                {
                    pictureboxes[item].Image = imglst.Images[item];
                }
      

  2.   

    for (int i = 0; i < 9; i++)
     {
      indexes.Insert(r.Next(0, indexes.Count - 1), i);
      //Thread.Sleep(10);
     }
    =>List<int> numList = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8 };            for (int i = 0; i < 9; i++)
                {
                    int num = r.Next(0, numList.Count);
                    while (indexes.Contains(numList[num]))
                    {
                        num = r.Next(0, numList.Count);
                    }
                    indexes.Add(numList[num]);
                    numList.Remove(numList[num]);
                }
      

  3.   

    List<int> numList = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8 };            for (int i = 0; i < 9; i++)
                {
                    int num = r.Next(0, numList.Count);
                    indexes.Add(numList[num]);
                    numList.Remove(numList[num]);
                }这样
      

  4.   

    random.next(minValue,maxValue)得到minValue和maxValue之间的随机数,楼主的
    r.Next(0, indexes.Count - 1),其中indexes.Count-1大于0吗?