未将对象引用设置到对象的实例。不知道哪里错了?
ClassLibrary.rar
(44.3 KB)
还请有时间的朋友看看
public void Shuffle() { // throw new System.NotImplementedException(); Card[] newDeck=new Card[52]; bool[] assigned=new bool[52]; Random sourceGen=new Random(); for (int i = 0; i < 52; i++) { int destCard = 0; bool foundCard = false; while (foundCard == false) { destCard = sourceGen.Next(52); if (assigned[destCard] == false) foundCard = true; } assigned[destCard] = true; newDeck.CopyTo(cards, 0); } }你这个洗牌的方法写错了 你首先声明了 Card[] newDeck; 这时里边所有的Card对象都还没有实例化 也就是都等于null 你可以
public void RightShuffle(int ct) { for (int i = 0; i < ct; i++) { Random rdm = new Random(); int a = rdm.Next(52); int b = rdm.Next(52); Card cd = cards[a]; cards[a] = cards[b]; cards[b] = cd; } }