Re: Hashtable
From: Justin Rogers (Justin_at_games4dotnet.com)
Date: 05/24/04
- Next message: Daniel Jin: "RE: EventHandler and sender object"
- Previous message: Mickey Williams: "Re: confused with the ThreadPoolling"
- In reply to: MAY: "Re: Hashtable"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 May 2004 12:00:11 -0700
// Enumerate
ArrayList al = hash["a"] as ArrayList;
if ( al != null ) {
foreach(int i in al) {
Console.WriteLine(i);
}
}
// Adding an element
public void AddKeyedValue(string key, int value) {
ArrayList al = hash[key] as ArrayList;
if ( al == null ) {
al = new ArrayList();
hash[key] = al;
}
al.Add(value);
}
-- Justin Rogers DigiTec Web Consultants, LLC. Blog: http://weblogs.asp.net/justin_rogers "MAY" <patwyh@hotmail.com> wrote in message news:u4FNTtbQEHA.1620@TK2MSFTNGP12.phx.gbl... > Hi Jon, > > Can you post a simple code to retreive the data? > > Thx again. > > MAY > > > "MAY" <patwyh@hotmail.com> ¦b¶l¥ó > news:%23eQaYebQEHA.1960@TK2MSFTNGP10.phx.gbl ¤¤¼¶¼g... > > Thx :) i got it > > > > MAY > > "Jon Skeet [C# MVP]" <skeet@pobox.com> ??? > > news:MPG.1b1c4262a759911198a9d3@msnews.microsoft.com ???... > > > MAY <patwyh@hotmail.com> wrote: > > > > hi, > > > > > > > > if i have the data : > > > > > > > > a 123 > > > > 1213 > > > > 3243 > > > > > > > > b 32 > > > > 312 > > > > 342 > > > > > > > > c 3243 > > > > 231 > > > > > > > > > > > > > > > > how to use hashtable to save these data, and how to retrieve these? > Thx. > > > > > > The normal way would be to have the mapping for each character to an > > > ArrayList of ints. For instance: > > > > > > ArrayList al = new ArrayList(); > > > hash["a"] = al; > > > al.Add(123); > > > al.Add(1213); > > > al.Add(3243); > > > > > > al = new ArrayList(); > > > hash["b"] = al; > > > al.Add(32); > > > al.Add(312); > > > al.Add(342); > > > > > > etc > > > > > > When you fetch from the hash, cast the returned value to ArrayList, and > > > then you can iterate through the integers. > > > > > > -- > > > Jon Skeet - <skeet@pobox.com> > > > http://www.pobox.com/~skeet > > > If replying to the group, please do not mail me too > > > > > >
- Next message: Daniel Jin: "RE: EventHandler and sender object"
- Previous message: Mickey Williams: "Re: confused with the ThreadPoolling"
- In reply to: MAY: "Re: Hashtable"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|