c# - Object reference not set to an instance of an object -


public player(string name, list<card> cards) {    this.name = name;    try    {       this.stack.insertcards(cards);//here nullreferenceexeption    }    catch (exception e)    {                       throw e;    } }  public void insertcards(list<card> cards) {    stack.addrange(cards); }  public list<card> getsevencards() //the player gets cards function {    list<card> list = new list<card>();    int ran;    random r = new random();    (int = 0; < 7; i++)    {       ran = r.next(0, stack.count()-1);       list.add(stack[ran]);       stack.removeat(ran);    }    return list; } 

the stack gets cardlist of 7 cards

should be:

this.stack.insertcards(getsevencards()); 

and create new instance of stack.

because cards null. fill them function first.

can't more things, because didn't give more information definitions. there should more codes.


Comments

Popular posts from this blog

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -