P
Paul
thanks for the additional information, will give it a try. I had to add the
public keyword to the class interface values to gain access when copying data
from the hash table out to an array list.
Public class foo
{
public String name;
--
Paul G
Software engineer.
public keyword to the class interface values to gain access when copying data
from the hash table out to an array list.
Public class foo
{
public String name;
--
Paul G
Software engineer.
Peter Duniho said:Hi thanks that worked!, just wondering if you know if there is an easy
way to
sort the hash table, say based on name alphabetical? I can look through
the
hash table methods as well to see if there is anything.
The Hashtable itself can't be sorted. But you can certainly copy the data
from the Hashtable and sort that.
You could copy the keys to an Array or List<T> and sort it using a custom
comparer (one that only looks at the field you want sorted). For example
(using Jon's sample):
Hashtable grouped = ...;
/* initialize hash table... */
/* then... */
ICollection keys = grouped.Keys;
Foo[] keyArray = new Foo[keys.Count];
keys.CopyTo(keyArray, 0);
Array.Sort(keys, delegate(Foo foo1, Foo foo2) { return
foo1.name.CompareTo(foo2.name); });
Then the "keys" array will be all of your data items, sorted by name.
You would probably do well to just browse through the System.Collections
and System.Collections.Generic namespaces. There are a number of
different kinds of collections, each of which providing different
functionality appropriate to different needs.
Pete