|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Compare object[] Not Working for Hashtable Keysnot matchng with the following code. What is a better way to do this. HybridDictionary hd = new HybridDictionary(13); object[] oneKey = new object[]{"a", 0 , "a" }; object[] oneValue = new object[]{"a", 0 , "a" }; object[] twoKey = new object[]{"b", 0 , "b" }; object[] twoValue = new object[]{"b", 0 , "b" }; hd.Add( oneKey , oneValue ); hd.Add( twoKey , twoValue ); object[] testKey = new object[]{"a", 0 , "a" }; IDictionaryEnumerator hdEnum = hd.GetEnumerator(); while( hdEnum.MoveNext() ) { if ( testKey == (object[])hdEnum.Key ) { Console.WriteLine("match."); } } Thanks. localhost <primpi***@cohort.ces> wrote:
Show quote > I have a HybridDictionary with a key containing an object array. It's You're testing for reference equality, which certainly isn't true. You > not matchng with the following code. What is a better way to do this. > > HybridDictionary hd = new HybridDictionary(13); > > object[] oneKey = new object[]{"a", 0 , "a" }; > object[] oneValue = new object[]{"a", 0 , "a" }; > object[] twoKey = new object[]{"b", 0 , "b" }; > object[] twoValue = new object[]{"b", 0 , "b" }; > hd.Add( oneKey , oneValue ); > hd.Add( twoKey , twoValue ); > > object[] testKey = new object[]{"a", 0 , "a" }; > > IDictionaryEnumerator hdEnum = hd.GetEnumerator(); > while( hdEnum.MoveNext() ) > { > if ( testKey == (object[])hdEnum.Key ) > { > Console.WriteLine("match."); > } > } need to write your own array comparison class. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||