| re: "Sorting" a hashtable
Ah, now that I've read your question properly...... ;)
Yeah sorry about that. So the attribute has some kind of parameter that
would become the sort key?
I think you will need to write a custom comparer, as the only way to get
hold of the attributes is through the type.
"JezB" <jezbroadsword@blueyonder.co.uk> wrote in message
news:O5gb125VEHA.2972@TK2MSFTNGP11.phx.gbl...[color=blue]
> Won't that just order by the hashtable key ? I want to order by an[/color]
attribute[color=blue]
> in the hashtable values.
>
> "John Wood" <spam@isannoying.com> wrote in message
> news:eP$Ihb5VEHA.2184@TK2MSFTNGP10.phx.gbl...[color=green]
> > You can instantiate the ArrayList from the Keys property of the[/color][/color]
hashtable.[color=blue][color=green]
> > Then sort the ArrayList (no need to write a comparer). You can then[/color]
> iterate[color=green]
> > through the keys in the arraylist and lookup the associated value in the
> > hashtable.
> >
> > If you don't want that final step (coz of performance), you could write[/color][/color]
a[color=blue][color=green]
> > comparer for the object (assuming the key is also stored in the object),
> > instantiate the ArrayList from the Values property, and then sort using[/color]
> your[color=green]
> > custom comparer. The ArrayList will then contain a sorted list of your
> > objects.
> >
> > "JezB" <jezbroadsword@blueyonder.co.uk> wrote in message
> > news:eDxyCR5VEHA.3016@tk2msftngp13.phx.gbl...[color=darkred]
> > > I have a hashtable (h) of class objects keyed by a string (k) - the[/color][/color]
> class[color=green][color=darkred]
> > > (c) object stored in each hastable entry has two attributes (a1 and[/color][/color][/color]
a2).[color=blue][color=green][color=darkred]
> > >
> > > I want to iterate through the entries of the hashtable by ordering by[/color][/color]
> one[color=green]
> > of[color=darkred]
> > > the attributes of the class (a1 or a2).
> > >
> > > How can this easily be achieved ? I think I have to copy to an[/color][/color][/color]
ArrayList[color=blue][color=green][color=darkred]
> > > then write an IComparer - but I'm not sure if this is the best way.
> > >
> > > Any advice appreciated.
> > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color] |