i have never programmed in c# in life understand java enough. running program , everytime keeps saying count/ienumerator has not been implemented. have tried various different ways , have put in various different locations in file. understand extremely easy thing don't understand it. presume these sort of methods don't ask why sitting instance variables are.
can explain me how use collections? collection being used here ireadonlycollection implemented ipackofcards implemented in class.
are c# interfaces allowed have implementation in them?
using system; using codedtests.nunit; using system.collections.generic; using system.collections.objectmodel; namespace codedtests.nunit { public class packofcards : ipackofcards { private const int numcards = 52; private int cardsinpack; //private card[] cards; private collection<icard> pack = new collection<icard>(); int count { get; } public ienumerator<icard> getenumerator(){return pack.getenumerator();} //ienumerator ienumerable.getenumerator(){ return getenumerator();} public collection<icard> create() { cards = new card [numcards]; string [] values = {"ace","two","three","four","five","six","seven","eight","nine","ten","jack","queen","king"}; string [] suits = {"hearts", "diamonds", "spades", "clubs"}; int cardsinpack = 0; for(int = 0 ; i<suits.length; i++){ for(int j = 0; j<values.length; j++, cardsinpack++){ cards[cardsinpack]= new card(values[j], suits[i]); } } return new pack; } public void shuffle(){ random num = new random(); for(int = 0; i<numcards;i++){ int ran = num.next(numcards); card temp = cards[ran]; cards[ran] = cards[i]; cards[i] = temp; } } public icard takecardfromtopofpack (){ int topcard = 0; icard cardremoved = cards[topcard]; for(int = 0;i<numcards-1;i++){ cards[i]=cards[i+1]; } cards[cardsinpack] = null; cardsinpack--; return cardremoved; } } } public class card : icard { private string value; private string suit; public card(string v, string s) { value = v; suit = s; } public string getvalue(){ return value; } public string getsuit(){ return suit; } public string tostring(){ return value+" of "+suit; } } } public interface ipackofcards : ireadonlycollection<icard> { void shuffle (); icard takecardfromtopofpack (); } public interface ipackofcardscreator { ipackofcards create (); } public class packofcardscreator : ipackofcardscreator { public ipackofcards create()
ipackofcards implements ireadonlycollection. means have implement members of ireadonlycollection in addition members of ipackofcards, namely count property , getenumerator method, documented here. interface members have public, count property private. didn't specify accessibility, it's defaulted private.
Comments
Post a Comment