c#中编写一个程序,创建Hashtable实例,内含多名学生的姓名和成绩,要求:输出所有学?

如题所述

using System;
using System.Collections;

class Program
{
public static void Main()
{
Hashtable ht = new Hashtable();
ht.Add("1", new Student { Name = "张三", Grade = "100" });
ht.Add("2", new Student { Name = "李四", Grade = "98" });
ht.Add("3", new Student { Name = "王五", Grade = "82" });

foreach (string k in ht.Keys)
{
Student s = ht[k] as Student;
Console.WriteLine(s.Name + ": " + s.Grade);
}
}
}
class Student
{
public string Name { get; set; }
public string Grade { get; set; }
}

温馨提示:答案为网友推荐,仅供参考