localhost <(E-Mail Removed)> wrote:
> I have a HybridDictionary with a key containing an object array. It's
> 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.");
> }
> }
You're testing for reference equality, which certainly isn't true. You
need to write your own array comparison class.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too