You can specify an external comparer (IComparer) for those cases when the
key object does not implement ICompareable.

HTH,
Saar
----- Original Message -----
From: "Nathan Rogers (Public Mail)" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 02, 2002 02:47
Subject: [ADVANCED-DOTNET] Keys in collections


System.Collections.Hashtable raises a runtime exception if you attempt
to do a lookup on a key that doesn't implement IComparable (which makes
sense).

But I'm not sure why the "key" parameter in this (and other key-based
collections) class' method delcarations is "object", rather than
"IComparable", which would mean this error could be caught at compile
time.  This seems to stem from the declarations in IDictionary

My first thought is that it was done to support the use of value types
as keys (because I wasn't sure if they could implement interfaces - they
can't in Java), but they can in the CLS successfully be cast to
IComparable and indeed the object browser shows that things like Int32
implement IComparable.

My second thought is that it was to support enumerable-only collections
(without any key based lookup).  Seems a little weak though.  Can anyone
see another reason or flaw in my thinking?

Cheers

Nath

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to