vb.net - How to sort a list of dates and sort another list into the same order? vb .net -


apologies if question worded awkwardly, don't know better way explain need.

i have list of dates , list of activities happened on dates so:

datelist(0) = 06/01/2015   activitylist(0) = kayaking datelist(1) = 04/01/2015   activitylist(1) = rock climbing datelist(2) = 01/01/2015   activitylist(2) = hiking datelist(3) = 05/01/2015   activitylist(3) = orienteering 

so on 06/01/2015 kayaking selected activity , on.

what want know is there way reorder both lists, preferably without using loop , increment, in chronological order being end result:

datelist(0) = 01/01/2015   activitylist(0) = hiking datelist(1) = 04/01/2015   activitylist(1) = rock climbing datelist(2) = 05/01/2015   activitylist(2) = orienteering datelist(3) = 06/01/2015   activitylist(3) = kayaking 

is there way in vb .net using visual express 2013? thank in advance -tom

it hard tell if shown list(of t) or array. listing seems seems more data display since otherwise has syntax problems. arrays assumed.

if lastdate , activity closely related, better keep them in class rather storing individual bits of data in own container , dissociated each other. that, class:

public class activity     public property name string     public property lastdate datetime     public property rating integer      public sub new(n string, dt datetime)         name = n         lastdate = dt         rating = 1          ' default     end sub  end class 

then (real) list store them:

actlist = new list(of activity)  dim act activity act = new activity("kayaking", #4/1/2015#) actlist.add(act)  ' short form, no temp var: actlist.add(new activity("cat herding", #6/1/2015#)) actlist.add(new activity("rock climbing", #1/1/2011#)) actlist.add(new activity("bicycling", #6/1/2014#)) 

lists easier manage arrays because not have resize them or know how big make them in advance. sort list date, use orderby extension :

actlist = actlist.orderby(function(d) d.lastdate).tolist ' display result: each activity in actlist     console.writeline("act: {0}  last date: {1}", a.name, a.lastdate.toshortdatestring) next 

results:

act: rock climbing last date: 1/1/2011
act: bicycling last date: 6/1/2014
act: kayaking last date: 4/1/2015
act: cat herding last date: 6/1/2015


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -