C# Hashtable

时间:2013-10-04 16:45:54
【文件属性】:

文件名称:C# Hashtable

文件大小:2KB

文件格式:CS

更新时间:2013-10-04 16:45:54

Hashtable

// Hashtable2.cs // 给Hashtable添加元素的示例 using System; using System.Collections; public class Test { public static void Main() { Hashtable table = new Hashtable(); table.Add("Sunday", "星期天"); table.Add("Monday", "星期一"); table.Add("Tuesday", "星期二"); table.Add("Wednesday", "星期三"); table.Add("Thursday", "星期四"); table.Add("Friday", "星期五"); table.Add("Saturday", "星期六"); Console.WriteLine("表中的所有元素包括:"); IEnumerator e = table.GetEnumerator(); while (e.MoveNext()) { DictionaryEntry de = (DictionaryEntry)e.Current; Console.WriteLine("{0}-{1}", de.Key, de.Value); } try { table.Add("Wednesday", "周3"); } catch (ArgumentException ex) { Console.WriteLine(ex.Message); } Console.WriteLine("表中的所有元素包括:"); e = table.GetEnumerator(); while (e.MoveNext()) { DictionaryEntry de = (DictionaryEntry)e.Current; Console.WriteLine("{0}-{1}", de.Key, de.Value); } try { table["Wednesday"] = "周3"; } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine("表中的所有元素包括:"); e = table.GetEnumerator(); while (e.MoveNext()) { DictionaryEntry de = (DictionaryEntry)e.Current; Console.WriteLine("{0}-{1}", de.Key, de.Value); } } }


网友评论