Re: ContainsKey() does not find key
- From: "Jon Skeet [C# MVP]" <skeet@xxxxxxxxx>
- Date: Mon, 25 Jun 2007 05:28:59 -0700
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
.
- Follow-Ups:
- Re: ContainsKey() does not find key
- From: Andrus
- Re: ContainsKey() does not find key
- References:
- ContainsKey() does not find key
- From: Andrus
- ContainsKey() does not find key
- Prev by Date: Re: recursive GetEnumerator()
- Next by Date: Re: recursive GetEnumerator()
- Previous by thread: Re: ContainsKey() does not find key
- Next by thread: Re: ContainsKey() does not find key
- Index(es):