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。”麻烦各位大哥大姐帮忙看看,我是新手,不怎么懂,如果各位有更好地实现方法,也可以教教我啊,谢谢了
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。”麻烦各位大哥大姐帮忙看看,我是新手,不怎么懂,如果各位有更好地实现方法,也可以教教我啊,谢谢了
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];
}
{
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]);
}
{
int num = r.Next(0, numList.Count);
indexes.Add(numList[num]);
numList.Remove(numList[num]);
}这样
r.Next(0, indexes.Count - 1),其中indexes.Count-1大于0吗?