当前位置:编程学习 > C#/ASP.NET >>

谁帮我看看这段代码哪地方出错了

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication11
{
    class student
    {
        public string name;
        public char sex;
        public student(string name1, char sex1)
        {
            name = name1;
            sex = sex1;
        }
        public string answer()
        {
            return "mingzi:" + name + "xingbie:" + sex;
        
        }
    }

    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 ();
} --------------------编程问答--------------------
引用 2 楼 superliu1122 的回复:
IEnumerator ie = c.GetEnumerator();

正解
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,