c# - AddDictionary object to list of objects -


i have list of objects:

public list<idnamepair> languages {     { return languages; }     set { languages = value; } } 

how add languages list above dictionary of same idnamepair?

protected dictionary<int, list<idnamepair>> countrylanguages { get; set; } 

i'm trying this:

subjectbaseinfo.languages = countrylanguages; 

but error:

cannot implicitly convert type 'system.collections.generic.dictionary>' 'system.collections.generic.list'

idnamepair contains id , name.

the 2 types different. subjectbaseinfo.languages single list<idnamepair>, whereas countrylanguages series of list<idnamepair> indexed int.

so assignment have couple of possibilities.

if assume subjectbaseinfo has id property might wanting this:

subjectbaseinfo.languages = countrylanguages[subjectbaseinfo.id]; 

however, if subjectbaseinfo doesn't have id might want of idnamepair of lists in countrylanguages new single list. in case can this:

subjectbaseinfo.languages = countrylanguages.selectmany(kvp => kvp.value).tolist();  

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -