问题描述
刚学C#不久,碰到了一个很奇怪的问题。运行的时候不能得到正确的结果但是如果插入断点。单步执行就能得到结果。很奇怪。代码如下。usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingClassLib;namespace_4{publicclassProgram{publicint[]fivecards=newint[5];staticvoidMain(string[]args){Deckmydeck=newDeck();mydeck.Shufel();Programmypro=newProgram();mypro.getfivecard();for(inti=0;i<5;i++){inttemp=mypro.fivecards[i];Cardmycard=mydeck.getcard(temp);Console.WriteLine(mycard.ToString());}}publicvoidgetfivecard(){bool[]mybool=newbool[52];for(inti=0;i<5;i++){intdestcard=0;boolassgined=false;Randomr=newRandom();while(assgined==false){destcard=r.Next(52);if(assgined==false){fivecards[i]=destcard;assgined=true;}mybool[destcard]=true;}}}}}usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceClassLib{publicclassDeck{privateCard[]cards=newCard[52];publicCardgetcard(intcardnum){if(cardnum>=0&&cardnum<=51)returncards[cardnum];elsethrow(newSystem.ArgumentOutOfRangeException("cardnum",cardnum,"值必须在0到51之间"));}publicDeck(){for(intsuitcount=0;suitcount<4;suitcount++){for(intrankcount=1;rankcount<=13;rankcount++){cards[suitcount*13+rankcount-1]=newCard((Suit)suitcount,(Rank)rankcount);}}}publicvoidShufel(){Card[]newcard=newCard[52];bool[]assigned=newbool[52];for(inti=0;i<=51;i++){intdestcard=0;boolmybool=false;while(mybool==false){Randomr=newRandom();destcard=r.Next(52);if(assigned[destcard]==false)mybool=true;}assigned[destcard]=true;newcard[i]=destcard;}}}}usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceClassLib{publicenumSuit{Club,Heart,Spade,Diamond}publicenumRank{Ace=1,Two,Three,Four,Five,Six,Seven,Eight,Nine,Tem,Jack,Queen,King}publicclassCard{publicreadonlySuitsuit;publicreadonlyRankrank;privateCard(){}publicCard(Suitnewsuit,Ranknewrank){suit=newsuit;rank=newrank;}publicoverridestringToString(){return"The"+rank+"of"+suit+"s";}}}其中建了一个ClassLib的类库包含一个Deck的类和一个Crad类。主要是实现从谁机的52张牌中抽到5张谁机的牌,但是我得不到结果。谢谢!!!!!!!!!!!!!
解决方案
解决方案二:
这个问题你发了很多遍了,自己发的帖子自己不看吗...