class myHashtable
    {
        public Hashtable htResult = new Hashtable();
        public void AddItem(int _intNewItem)
        {
            int pkey = _intNewItem % 13;
            int i = 0;
            while (this.htResult.Contains(pkey) && i < 13)
            {
                pkey = (pkey + 1) % 13;
                i++;
            }
            if (i < 13)
                this.htResult.Add(pkey, _intNewItem);
            else
                Console.WriteLine("哈希表溢出");
        }
    }    class Program
    {
        static void Main(string[] args)
        {
            myHashtable myht = new myHashtable();
            int pValue = 0;
            Console.WriteLine("输入10个整数值");            for (int i = 0; i < 10; i++)
            {
                pValue = Convert.ToInt32(Console.ReadLine());
                myht.AddItem(pValue);                      //这行有错误
            }
            foreach (System.Collections.DictionaryEntry pair in myht.htResult)
            {
                Console.WriteLine("{0}->[1}", pair.Key, pair.Value);
            }
        }
    }
大家帮忙找一下
谢谢~

解决方案 »

  1.   

    你代码有误
    for   (int   i   =   0;   i   <   10;   i++) 
                            { 
                                    pValue   =   Convert.ToInt32(Console.ReadLine()); 
                                    myht.AddItem(pValue);                                             //这行有错误 
                            } 
    这个for循环你是想循环找到输入的10个整数值,是吗?但是这样写根本行不通啊
      

  2.   

                Console.WriteLine("输入10个整数值,并以,隔开");
                string str = Console.ReadLine();
                string[] arrStr = str.Split(',');
                for (int i = 0; i < 10; i++)
                {
                    pValue = Convert.ToInt16(arrStr[i]);
                }
    这个可以取得输入的10个数字,但是你写的AddItem()有误,不是很明白你的意思
      

  3.   

    看不懂楼主的函数。
    foreach   (System.Collections.DictionaryEntry   pair   in   myht.htResult) 
    似乎是这句的问题,
    提示,输入的字符串格式不对。
    myht.htResult总觉得这句很怪
      

  4.   

    foreach   (System.Collections.DictionaryEntry   pair   in   myht.htResult) 
                            { 
                                    Console.WriteLine("{0}-> [1}",   pair.Key,   pair.Value); 
                            } 
    这里错了,但是为什么提示报告错了呢?