c# - Linq ToDictionary() Implementation -


i have list follows:

list<person> people = new list<person>() {     new person() { firstname = "bob",lastname="test",empid="1234" },     new person() { firstname = "bob",lastname="t",empid="1234" },     new person() { firstname = "jane",lastname="test",empid="1234" },     new person() { firstname = "jane",lastname="t",empid="1234" } }; 

here person fields unique if add firstname , lastname.

if use

  dictionary<string, person> dictionary = people.todictionary(v => v.firstname);  

then item exist exception.

and can't use lastname aswell.

so need use combination of firstname , lastname , value can saved firstname;#lastname in dictionary key

i new c# development

any suggestions helpful.

regards

anand

you can use kinds of expressions inside linq delegate. try

 dictionary<string, person> dictionary = people.todictionary(v => v.firstname + ";#" + v.lastname); 

Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -