vb.net - Best data structure to store key value pairs when the following operations are required -
i need store list of key value pairs. key value pair used multiple classes, ideally list of structure define.
public structure person public id integer public weight decimal end structure 'all use person class census class importpeople class determinebestdiet etc - i need sort value
- i need remove person (by person.id) or add new key value pair (and re-sort after each add)
- i need sum total of values
seems people use dictionaries , hack around.
you can use list<person> work
using list.sort method:
thelist.sort(function(x, y) x.age.compareto(y.age))
using orderby extension method:
thelist = thelist.orderby(function(x) x.age).tolist()
details can see post: https://stackoverflow.com/a/11736001/1050927just remove list , call
sortororderby.
depends on want do, can useorderbyskip,takespecific nth person after sort.just
sumit
personlist.sum(function(per) per.weight)
and believe dictionary can same too, can't reuse person only.
Comments
Post a Comment