public Player(string name, List<Card> cards)
{
this.name = name;
try
{
this.stack.insertCards(cards);//Here is the NullReferenceExeption
}
catch (Exception e)
{
throw e;
}
}
public void insertCards(List<Card> cards)
{
stack.AddRange(cards);
}
public List<Card> GetSevenCards() //the Player gets the Cards from this function
{
List<Card> list = new List<Card>();
int ran;
Random r = new Random();
for (int i = 0; i < 7; i++)
{
ran = r.Next(0, stack.Count()-1);
list.Add(stack[ran]);
stack.RemoveAt(ran);
}
return list;
}
the stack gets a cardlist of 7 Cards
Should be:
and create new instance of stack.
Because cards are null. Fill them with function first.
Can’t say more things, because you didn’t give more information about definitions. There should be more codes.