Results 1 to 1 of 1
Thread: Dictionary
Hybrid View
-
28th December 2009 14:16 #1
Dictionary
, , int string, string[]:
1.
debug , , ContainsKey .
, , IEqualityComparer:
2.
debug , Equals . ( .)
Equals :
d1[new string[] { "a", "a" }], .Code:d1.Keys.Contains<string[]>(new string[] { "a", "a" }, new StringArrayComparer())
.
EDIT
:
Code:public int GetHashCode(string[] obj) { return 0; }
, , , .
, ContainsKey - Equals.
GetHashCode , :
Code:public int GetHashCode(string[] obj) { return obj[0].GetHashCode() ^ obj[1].GetHashCode(); }
EDIT2:
:
, , . , 1 .Code:public int GetHashCode(string[] obj) { return obj[0].GetHashCode() ^ obj[1].GetHashCode(); }
, , . :
GetHashCode , .Code:d1.Add(new string[] { "a", "a" }, "47"); d1.Add(new string[] { "b", "b" }, "b15"); d1.Add(new string[] { "c", "c" }, "b15");
, , , , "a", "b" "c" .
Last edited by ; 28th December 2009 at 16:49.




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in