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 
  1. i need sort value
  2. i need remove person (by person.id) or add new key value pair (and re-sort after each add)
  3. i need sum total of values

seems people use dictionaries , hack around.

you can use list<person> work

  1. 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/1050927

  2. just remove list , call sort or orderby.
    depends on want do, can use orderby skip , take specific nth person after sort.

  3. just sum it
    personlist.sum(function(per) per.weight)

and believe dictionary can same too, can't reuse person only.


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -