Autor Beitrag
Bex
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Win XP, Linux
C# (VS 2008), Java (Eclipse)
BeitragVerfasst: Mi 15.11.06 12:33 
Moin,

ich versuche, eine HashTable oder ein Dictionary mit einem selbst deklarierten Typ als Key zu bauen. In diesem habe ich Equals() und GetHashCode() implementiert.
Mein Problem ist, dass die ContainsKey()-Methode immer false zurückgibt, obwohl manche der Keys vorhanden sind. In die Equals()-Methode läuft das Programm gar nicht erst hinein.

Hat jemand eine Idee, wo das Problem liegen könnte? Muss man im eigenen Key ein bestimmtes Interface implementieren, damit das funktioniert?

Besten Dank!
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 15.11.06 12:41 
Hallo und :welcome:!

Das Beste wird es sein, wenn Du ein wenig Deines Sourcecodes zeigt. Dann kann gezielter helfen, sonst muss man soviel raten :zwinker:

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 15.11.06 12:51 
Ich habe gerade nochmal geschaut. Die Hilfe zu Dictionary.Comparer könnte Dir weiterhelfen

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Bex Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 47

Win XP, Linux
C# (VS 2008), Java (Eclipse)
BeitragVerfasst: Mi 15.11.06 13:08 
Hmm. Sorry, jetzt hab ich mir ein "anonymisiertes" Beispiel geschrieben, und schon funktioniert das - anscheinend wird Equals() nur aufgerufen, wenn GetHashCode() einen bestimmten Wert annimmt. Muss dann wohl an meinem Key liegen ...