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

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -