List< > Inside of Dictionary< K,List< > > (C#) -


student here.

working on current c# project. have create list< card > of playing cards, , dictionary< string,list< card > >.

list gets created independently, , dictionary holds collections of cards. cards can added or removed collections.

i'm having trouble adding card collection though. i've gotten index number of list user input, , trying update value in dictionary based on index.

the line throwing error here. error cannot implicitly convert type '< filename.cardclass >' system.collections.generic.list< filename.cardclass >'

i life of me can't figure out means , how resolve it..

_collections[input] = _cards[cardselectionindex]; 

here current code block:

    public void addtocollection()     {         printvaluescollections<string, list<card>>(_collections);         console.writeline("type in name of collection add card to:");         string input = console.readline();          bool found = _collections.containskey(input);         if (found)         {             console.writeline("list of current cards choose from:");              (int = 0; < _cards.count; i++)             {                     console.writeline("index number:\r\n"+i+"card info:\r\n"+_cards[i]+"\n");             }              console.writeline("type in index of card list add collection:");             string cardselection = console.readline();             int cardselectionindex = 0;             while (!int.tryparse(cardselection, out cardselectionindex))             {                 console.write("please enter number list above: ");                 input = console.readline();             }              _collections[input] = _cards[cardselectionindex];             _cards.removeat(cardselectionindex);         }         else             console.writeline("collection name not found.");     } 

i assume _collections type dictionary<string, list<card>> , _cards list<card>

so you're trying do:

//_collections[input] = _cards[cardselectionindex]; list<card> = _collections[input]; card b = _cards[cardselectionindex]; = b; 

notice types of a , b. correctly gives error: "cannot implicitly convert type '< filename.cardclass >' system.collections.generic.list< filename.cardclass >'"

what want add card list

list<card> = _collections[input]; card b = _cards[cardselectionindex]; a.add(b); 

or simply

_collections[input].add(_cards[cardselectionindex]); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -