473,504 Members | 13,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Hashtable

Hello

I defined:
Hashtable chan1 = new Hashtable(new
CaseInsensitiveHashCodeProvider(CultureInfo.Invari antCulture), new
InvariantComparer());

where:
public class InvariantComparer : IComparer
{
public CompareInfo m_compareInfo;
internal static readonly InvariantComparer Default = new
InvariantComparer();

internal InvariantComparer()
{
m_compareInfo = CultureInfo.InvariantCulture.CompareInfo;
}

public int Compare(Object a, Object b)
{/* compare my objects here */
DscRecord ra = a as DscRecord;
DscRecord rb = b as DscRecord;
if (ra.minute < rb.minute)
return 1;
else if (ra.minute > rb.minute)
return -1;

if (ra.second < rb.second)
return 1;
else if (ra.second > rb.second)
return -1;

if (ra.ssecond < rb.ssecond)
return 1;
else if (ra.ssecond > rb.ssecond)
return -1;

return 0;
}
}

but when i read data from hashtable:
IDictionaryEnumerator myEnumerator = chan.GetEnumerator();
while ( myEnumerator.MoveNext() )
{
......
}

i receive them "unsorted". Why ?
Is there any other way to read records from HashTable which is sorted by
key ?

Thanx
Michal
Nov 17 '05 #1
1 7188
vertigo <nu**@com.pl> wrote:
I defined:
Hashtable chan1 = new Hashtable(new
CaseInsensitiveHashCodeProvider(CultureInfo.Invari antCulture), new
InvariantComparer());
<snip>
i receive them "unsorted". Why ?
Because hashtables are fundamentally unsorted. They're maps, not lists.
Is there any other way to read records from HashTable which is sorted by
key ?


Well, you could use SortedList (which is actually a map - don't let the
poor naming deceive you) instead. That's what it's there for.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5219
by: JezB | last post by:
I have a hashtable (h) of class objects keyed by a string (k) - the class (c) object stored in each hastable entry has two attributes (a1 and a2). I want to iterate through the entries of the...
0
5344
by: Rudolph Araujo | last post by:
Hi, I needed to build a data grid in which the first column has hyperlinks rather than simple text. I found the following code on this newsgroup and it works fine except for one problem. When I...
2
1626
by: Vidyanand Kulkarni | last post by:
Hello everybody, can anybody tell me how how he sorting on hashtable is done in c# thanking in advance with regards vidyanand kulkarni
6
7812
by: Fred Morrison | last post by:
Do you know of a way to load a hash table with random key/value pairs (e.g., 2/"Two",1/"One",3/"Three") and then iterate through the entries in "sorted" (key sequence) order...
3
3752
by: Mark Gilkes | last post by:
Hi, I have an aspx page in which I am building a DataGrid control in the code-behind dynamically. The DataGrid is declared along with BoundColumns and bound to the datasource, then added to a...
11
7758
by: garyhoran | last post by:
Hi Guys, I have a collection that contains various attributes (stuff like strings, DateTime and Timespan) . I would like to access the collection in various orders at different points in the...
7
1274
by: cmdolcet69 | last post by:
Im trying to compare arrayindex slots in a array. I have an arraylist of size (n) and once all the arraylist slots are filled i would like to compare each slot so that they are all unique number. ...
2
1331
by: almurph | last post by:
H ieveryone, Can you help me please? I am trying to sort a hashtable but get the error: "Cannot implicity convert type void to System.Collections.ArrayList" I am doing the following: ...
1
1169
by: almurph | last post by:
H ieveryone, Can you help me please? I am trying to sort a hashtable but get the error: "Cannot implicity convert type void to System.Collections.ArrayList" I am doing the following: ...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.