© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4mo ago•
12 replies
Attikitty

✅ How does dictionary.ContainsKey() work?

i have a class that implements IEquatable and ICompareable (i think only iequatable is needed for this but i could do both so i did), yet when I try and use it as a key it doesn't seem to work.

here is a pretty much what I have, tho i can send the actual code if needed
ItemType item1 = ...
ItemType item2 = ...

var dict = new Dictionary<ItemType, int>();
dict.Add(item1, 3); // doesnt matter what the value is rn

console.write(item1.Equals(item2)); // returns true
console.write(dict.ContainsKey(item2)); // returns false???
ItemType item1 = ...
ItemType item2 = ...

var dict = new Dictionary<ItemType, int>();
dict.Add(item1, 3); // doesnt matter what the value is rn

console.write(item1.Equals(item2)); // returns true
console.write(dict.ContainsKey(item2)); // returns false???

what else do I need to do to make this function?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dictionary cant find via ContainsKey but it does exist
C#CC# / help
3y ago
ContainsKey
C#CC# / help
3y ago
How does marshalling work?
C#CC# / help
5mo ago
How does Dapper work
C#CC# / help
2y ago