我有这样一个数组
如{02,02,02,03,03,03,04,03,02..}
我想把这个数字消除重复还想求处重复值出现的次数
实现这样的显示结果
02 4,03 4,04,1
请问这样的功能我该怎样实现

解决方案 »

  1.   

    用hashtable存储数组,键是数字,值是出现次数
    写个判断如果hashtable中存在了数字了,就让值加1
      

  2.   


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Collections;namespace MyLesson
    {
        class Program
        {
            static void Main(string[] args)
            {            int[] number ={2,2,2,3,3,3,4,3,2};
                Hashtable table = new Hashtable();
                for (int i = 0; i < number.Length; i++)
                {
                    if (table.ContainsKey(number[i]))
                    {
                        table[number[i]]=Convert.ToInt32(table[number[i]])+1;
                    }
                    else
                    {
                        table.Add(number[i], 1);
                    }            }
                foreach (Object ob in table.Keys)
                {
                  Console.Write(  Convert.ToInt32(ob)+" "+table[ob]+",");
                }
                          
            }
        }
    }不知道你说的意思是不是这样