我试图随机化一个列表,然后把它放到一个图片框中。当我这样做时,我收到错误消息“索引超出范围。必须是非负数并且小于集合的大小”
这是随机的代码:
public class Dealer
{
public static Random rand = new Random();
public static List<Kort> KortenÄrBlandade = new List<Kort>();
public void Shuffle()
{
List<Kort> KortenÄrBlandade = new List<Kort>(deckOfCards.OrderBy(_ => rand.Next(0, deckOfCards.Count)));
}
}
这是调用该方法的代码
private void button1_Click(object sender, EventArgs e)
{
Spelare.Dealer deal = new Spelare.Dealer();
deal.Shuffle();
pictureBox1.Image = Spelare.Dealer.KortenÄrBlandade[2].img;
}