Re: ContainsKey() does not find key

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Jun 25, 12:25 pm, "Andrus" <kobrule...@xxxxxx> wrote:
I need to create object cache in memory.

Each object id can be composed from several string, integer and decimal type
values.

ContainsKey does not find existing key in this case.

How to force ContainsKey to compare object contents and find key?

By overriding Equals and GetHashCode, basically. If you implement
IEquatable<CacheKey> you'll be saved the boxing penalty too (IIRC).

Out of interest, do you have any particular reason to make CacheKey a
struct rather than a class?

Jon

.