谁帮我看看这段代码哪地方出错了
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication11
{
class student
{
public string name;
public char 易做图;
public student(string name1, char 易做图1)
{
name = name1;
易做图 = 易做图1;
}
public string answer()
{
return "mingzi:" + name + "xingbie:" + 易做图;
}
}
class Program
{
static void Main(string[] args)
{
Hashtable h = new Hashtable();
student p = new student("aa",'b');
h.Add("甲", p);
student p1 = new student("bb", 'c');
h.Add("乙", p1);
student p2 = new student("cc", 'd');
h.Add("丙", p2);
ICollection c = h.Values;
IEnumerator ie = h.GetEnumerator();
while (ie.MoveNext())
{
string s = ((student)ie.Current).answer();
Console.WriteLine(s);
}
Console.ReadKey();
}
}
}
--------------------编程问答-------------------- 提示什么错误了? --------------------编程问答-------------------- IEnumerator ie = c.GetEnumerator(); --------------------编程问答-------------------- static void Main (string[] args)
{
Hashtable h = new Hashtable ();
student p = new student ("aa", 'b');
h.Add ("甲", p);
student p1 = new student ("bb", 'c');
h.Add ("乙", p1);
student p2 = new student ("cc", 'd');
h.Add ("丙", p2);
//遍历一
foreach (DictionaryEntry de in h)
{
Console.WriteLine ((de.Value as student).answer () + " " + de.Key.ToString());
}
//遍历二
System.Collections.IDictionaryEnumerator enumerator = h.GetEnumerator ();
while (enumerator.MoveNext ())
{
Console.WriteLine ((enumerator.Value as student).answer () + " " + enumerator.Key.ToString ());
}
Console.ReadLine ();
} --------------------编程问答--------------------
正解
补充:.NET技术 , C#