首页 > 其他 > 详细

SamplesHashtable

时间:2019-03-19 10:12:19      阅读:108      评论:0      收藏:0      [点我收藏+]
 1 using System;
 2 using System.Collections;
 3 
 4 public class SamplesHashtable  
 5 {
 6     public static void Main()  
 7     {
 8         Hashtable myHT = new Hashtable();
 9 
10         myHT.Add("Ton V. Bergyk", "023-010-66756");
11         myHT.Add("Tom Sony", "086-010-27654");
12         myHT.Add("Mr. John", "071-222-33445");
13 
14         myHT["Mr. John"] = "071-222-33445"; //加入或修改
15 
16         PrintKeysAndValues( myHT );
17         PrintByKeys( myHT );
18     }
19 
20     public static void PrintKeysAndValues( Hashtable myList )  
21     {
22         IDictionaryEnumerator myEnumerator = myList.GetEnumerator();
23         while ( myEnumerator.MoveNext() )
24             Console.WriteLine("\t{0}:\t{1}", 
25                 myEnumerator.Key, myEnumerator.Value);
26         Console.WriteLine();
27     }
28 
29     public static void PrintByKeys( Hashtable myList )
30     {
31         IEnumerator ie = myList.Keys.GetEnumerator();
32         while( ie.MoveNext() )
33         {
34             object key = ie.Current;
35             object value = myList[ key ];
36 
37             Console.WriteLine("\t{0}:\t{1}", key, value );
38         }       
39         Console.WriteLine();
40 
41         foreach( string key in myList.Keys )
42         {
43             Console.WriteLine("\t{0}:\t{1}", key, myList[key] );
44         }
45     }
46 }

 

SamplesHashtable

原文:https://www.cnblogs.com/GoldenEllipsis/p/10556741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!