- 关 键 词:
using System;
using System.Collections;
using System.Text;
public class SamplesHashtable {
public static void Main() {
// Create and initialize a new Hashtable.
Hashtable table = new Hashtable();
//Student Name, Grade
table.Add("Jay", 100);
table.Add("Brian", 87);
table.Add("Rajesh", 92);
table.Add("Bill", 76);
table.Add("Brad", 84);
table.Add("Kit", 91);
table.Add("Vinaya", 80);
table.Add("Lakshan", 87);
// Display the properties and values of the Hashtable.
Console.WriteLine("Count: {0}", table.Count );
PrintTable( table );
Console.WriteLine();
int g = (int) table["Jay"];
Console.WriteLine ("Jay's grade is: {0}", g);
Console.WriteLine();
PrintItems ("All Names", table.Keys);
Console.WriteLine();
PrintItems ("All Grades", table.Values);
}
public static void PrintTable( Hashtable myList ) {
Console.WriteLine ("{0,-8} {1,-8}", "Name","Grade");
Console.WriteLine ("{0,-8} {1,-8}", "----","-----");
foreach (DictionaryEntry e in myList) {
Console.WriteLine ("{0,-8} {1,-8}", e.Key, e.Value);
}
}
public static void PrintItems(string title, IEnumerable myList ) {
Console.Write ("{0}: ", title);
StringBuilder sb = new StringBuilder();
foreach (object o in myList) {
sb.AppendFormat( "{0}, ", o);
}
sb.Remove (sb.Length-2,2);
Console.WriteLine(sb);
}
}保留地址 http://www.qqread.com/dotnet/k234158.html进入讨论组讨论。
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- VB.NET 入门教程 (22167次浏览)
- asp.net 实现购物车详细代码 (14312次浏览)
- C#版的网站新闻发布系统 (690次浏览)
- ASP.NET2.0轻松搞定统计图表 (651次浏览)
- 使用ASP.NET AJAX实现幻灯片效果 (604次浏览)
- ASP.NET如何存取 SQLServer数据库图片 (592次浏览)
- 如何制作Asp.Net界面模板 (582次浏览)
- ASP.NET中实现DataGrid数据排序 (580次浏览)
- VB.NET读写文本文件方法 (579次浏览)
- VC#初学入门:第一个Windows程序 (536次浏览)



