PC Review


Reply
Thread Tools Rate Thread

How Dictionary<TKey,TValue> is checking keys?

 
 
Shimon Sim
Guest
Posts: n/a
 
      13th Jun 2006
I have Dictionary that has custom class as its key. For that class I
implemented both Equals(object) and IComparable<T>. I keep getting
KeyNotFoudException.
What should I do?
Thanks
Shimon


 
Reply With Quote
 
 
 
 
Lebesgue
Guest
Posts: n/a
 
      13th Jun 2006
You should implement GetHashCode() by overriding this method from
System.Object in your class used as key.

"Shimon Sim" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have Dictionary that has custom class as its key. For that class I
>implemented both Equals(object) and IComparable<T>. I keep getting
>KeyNotFoudException.
> What should I do?
> Thanks
> Shimon
>



 
Reply With Quote
 
Shimon Sim
Guest
Posts: n/a
 
      13th Jun 2006
Thanks it worked.
Shimon
"Lebesgue" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You should implement GetHashCode() by overriding this method from
> System.Object in your class used as key.
>
> "Shimon Sim" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>I have Dictionary that has custom class as its key. For that class I
>>implemented both Equals(object) and IComparable<T>. I keep getting
>>KeyNotFoudException.
>> What should I do?
>> Thanks
>> Shimon
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serialize a Dictionary(Of TKey, Of TValue) Art Microsoft VB .NET 1 7th Jul 2009 04:25 PM
Dictionary<TKey, TValue> with user-defined class implementingIEquatable<T> as key craig.wenger@gmail.com Microsoft Dot NET Framework 1 1st Feb 2008 02:18 PM
Show only needed methods from a Dictionary<TKey, TValue> class member daohuy.hua@gmail.com Microsoft C# .NET 6 1st Jun 2007 02:40 PM
Using Dictionary<TKey,TValue> in .net compact framework 2.0 Daniel.Kristensen@gmail.com Microsoft Dot NET Compact Framework 2 11th Oct 2006 08:13 PM
threading: acessing a Dictionary<TKey,TValue> with foreach bonk Microsoft C# .NET 7 10th Aug 2006 07:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:09 AM.