|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Problem with Dictionary<T,U>.Keys enumerator returning invalid keysI'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?
Show quote
"Brian Richards" <bricha***@gmail.com> wrote in message What's the type of the key?news:uJUkCWNiGHA.4044@TK2MSFTNGP03.phx.gbl... > 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? If the key is a user defined type that doens't implement equality correctly, it's possible that you'd get keys back from the enumerator that can't be found in the dictionary. -cd
Show quote
"Brian Richards" <bricha***@gmail.com> wrote in message shouldn't that be bool foo = dict.ContainsKey(key);news:uJUkCWNiGHA.4044@TK2MSFTNGP03.phx.gbl... > 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 SP Show quote > } > > Does anyone know what kinds of circumstances could cause this? > > |
|||||||||||||||||||||||