<·½·¨Ò»>int[] arr ={ 12, 12, 12, 13, 13, 14, 14, 14, 14, 0 };
Dictionary dic = new Dictionary();
foreach (int i in arr)
{
if (dic.ContainsKey(i))
dic = dic + 1;
else
dic.Add(i, 1);
}
//²é¿´½á¹û
foreach (int j in dic.Keys)
{
richTextBox2.Text += j.ToString() + ¡°µÄ¸öÊýÓУº¡¡¡± + dic[j] + ¡°¸ö\n¡±;
}
<·½·¨¶þ>int[] arr = { 12, 12, 12, 13, 13, 14, 14, 14, 14, 0 };
var query =
from a in arr
group arr by a into g
orderby g.Count()
select new
{
g.Key,
count = g.Count()
};
foreach (var i in query)
{
Console.WriteLine(¡°{0}³öÏÖ{1}´Î¡±, i.Key, i.count);
}