Test HashCode

 1         static void TestHashCode()
 2         {
 3             const string str1 = "0.89265452879139"; // 相同的 Hash
 4             const string str2 = "0.280527401380486"; // 相同的 Hash
 5 
 6             var hs = new HashSet<string> { str1, str2 };
 7 
 8             Console.WriteLine(hs.Count);
 9             Console.WriteLine(hs.Contains(str1));
10             Console.WriteLine(hs.Contains(str2));
11 
12             //   .net   2.0   
13             Console.WriteLine(str1.GetHashCode());
14             Console.WriteLine(str2.GetHashCode());
15 
16             var dict = new Dictionary<string, string> { {str1, str1}, {str2, str2} };
17 
18             Console.WriteLine(dict.Count);
19 
20             string outStr;
21 
22             dict.TryGetValue(str1, out outStr);
23             Console.WriteLine(outStr);
24 
25             dict.TryGetValue(str2, out outStr);
26             Console.WriteLine(outStr);
27 
28             Console.ReadKey();
29         }

 

posted @ 2014-03-13 10:39  H.Q.Cai  阅读(178)  评论(0)    收藏  举报