470,855 Members | 1,309 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,855 developers. It's quick & easy.

Problem with Dictionary<T,U>.Keys enumerator returning invalid keys

I'm experiencing some wierd behavior with a Dictionary<T,U> class using
foreach loops, such that the Key returned in the foreach is not contained in
the dictionary.

code:

Dictionary<A, B> dict;
.....
foreach(A key in dict.Keys)
{
bool foo = dict.ContainsKey(A); //returning false
}

Does anyone know what kinds of circumstances could cause this?

Jun 5 '06 #1
1 1228
"Brian Richards" <br*******@gmail.com> wrote:
I'm experiencing some wierd behavior with a Dictionary<T,U> class using
foreach loops, such that the Key returned in the foreach is not contained in
the dictionary.

code:

Dictionary<A, B> dict;
....
foreach(A key in dict.Keys)
{
bool foo = dict.ContainsKey(A); //returning false
}

Does anyone know what kinds of circumstances could cause this?


What type is A? Has it had its Equals() and GetHashCode() methods
overridden? If so, are the instances mutable after they have been
constructed? If so, have they been modified after adding to the
dictionary?

-- Barry

--
http://barrkel.blogspot.com/
Jun 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Jan-Erik Meyer-Lütgens | last post: by
reply views Thread by Golawala, Moiz M (GE Infrastructure) | last post: by
90 posts views Thread by Christoph Zwerschke | last post: by
3 posts views Thread by Beorne | last post: by
4 posts views Thread by =?Utf-8?B?YW1pcg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.