How do I sort by a selected dictionary value in person?
Example: Order list of "person" order descending from "car" price
Is it possible with one of those fancy lambda / linek equations?
Public category people {list & lt; Person & gt; Person {receive; Set; }} Public Sector Person {Public Dictionary & lt; String, string & gt; Cars {Get; Set; } Public Dictionary & lt; String, string & gt; Go home; Set; } Public Dictionary & lt; String, string & gt; Banks receive { Set; }} ................ people = new people (); People.paras = new list & lt; Person & gt; {New person {cars = new dictionary & lt; String, string & gt; {{"Volvo", "340050"}, {"BMW", "50545000"}}, homes = new dictionary & lt; String, string & gt; {{"Haveli", "100040000"}, {"Cardboard Box", "112"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "12500330000"}, {"caman", "12000000"}}}, new person {cars = new dictionary & lt; String, string & gt; {{"Volvo", "34023200"}, {"BMW", "5003300"}}, homes = new dictionary & lt; String, string & gt; {{"Haveli", "1000330000"}, {"Cardboard Box", "277"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "12500044000"}, {"caman", "12000000"}}}, new person {cars = new dictionary & lt; String, string & gt; {{"Volvo", "3554000"}, {"BMW", "50023200"}}, homes = new dictionary & lt; String, string & gt; {{"Mansion", "1006600000"}, {"Cardboard Box", "244"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "125000544000"}, {"Cayman", "12000777000"}}}}; Edit / example results: The result will be a new or re-order list based on the value contained in each person's dictionary
person - & gt; Cars - & gt; {"Volvo", "34023200"}
Person - & gt; Cars - & gt; {"Volvo", "3554000"}
Person - & gt; Cars - & gt; {"Volvo", "340050"}
A new or rearranged list will look like this:
people.Persons = New list & lt; Person & gt; {New person {cars = new dictionary & lt; String, string & gt; {{"Volvo", "34023200"}, {"BMW", "5003300"}}, homes = new dictionary & lt; String, string & gt; {{"Haveli", "1000330000"}, {"Cardboard Box", "277"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "12500044000"}, {"caman", "12000000"}}}, new person {cars = new dictionary & lt; String, string & gt; {{"Volvo", "3554000"}, {"BMW", "50023200"}}, homes = new dictionary & lt; String, string & gt; {{"Mansion", "1006600000"}, {"Cardboard Box", "244"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "125000544000"}, {"Cayman", "12000777000"}}}, new person {car = new dictionary & lt; String, string & gt; {{"Volvo", "340050"}, {"BMW", "50545000"}}, homes = new dictionary & lt; String, string & gt; {{"Haveli", "100040000"}, {"Cardboard Box", "112"}}, Bank = New Dictionary & lt; String, string & gt; {{"Swiss", "12500330000"}, {"Cayman", "12000000"}}}};
Here's a nifty trick; Originally, a word can be considered as a word that is called the quilputer & lt; & Gt; Objects.
dictionary & lt; Int, string & gt; MyDictionary = New Dictionary & lt; Int, string & gt; (); The dictionary is now on the list, it is easy to sort through a list via LINQ:
dictionary < Int, string & gt; Sample = New Dictionary & lt; Int, string & gt; {{1, "sample"}, {2, "another sample"}}; List given by Var = list = sample. OrderB (x = & gt; x.Value) .Oolist (); Of course, the big problem is that you will need to sort and organize a dictionary - it's not actually an operation that is actually grouped with the concept of a dictionary. (It's more for quick access to specific elements through a certain key) The problem description you write about seems strange; You can order cars for a specific person, but are you trying to find each person according to the value of each person? It is also easy to:
list & lt; PersonCarDetails & gt; AllStuff = new list & lt; PersonCarDetails & gt; (); Fourhake (different person in person) allStuff.AddRange (person.Cars.Select (x => New PersonCarDetails {PersonId = person.Id, CarName = x.Key, CarId = x.Value}) ToList ()); // All the Stuff now has a list of PersonCarDetails, and after that you can order: var list given = all the stuff. Orderbie (x = & gt; x.CarId). Ollist ();
Comments
Post a Comment