I have never programmed in C# in my life but i understand java well enough. I am running this program and everytime it keeps saying count/IEnumerator has not been implemented. I have tried various different ways and have put it in various different locations in file. I understand that this will be an extremely easy thing to do but I don't understand it. I also presume these are some sort of methods so don't ask why they are sitting where the instance variables are.
Can someone explain to me how to use collections? The collection being used here is ireadonlycollection which is implemented by IPackOfCards that is implemented in this class.
Are C# interfaces allowed to 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 i = 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 i = 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 i = 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()
IPackOfCardsinterface?IPackOfCardsinterface in your class, but actually it's not been implemented. If you right-click on the interface name in yourpublic class PackOfCards : IPackOfCardsdeclaration, and selectImplement Interface -> Implicitly(or explicitly), this will stub out the correct methods for you and should point you in the right direction. Hope that helps!