C#如何用统计数组中相同元素个数
如数组string[]value={“DFF11”,“DFF11”,“RFF11”,“RFF11”,“RFF11”,“CFF11”}如何统计相同元素的个数。...
如数组string[] value = {“DFF11”,“DFF11”,“RFF11”,“RFF11”,“RFF11”,“CFF11”}如何统计相同元素的个数。
展开
1个回答
2012-11-19
展开全部
string[] value = new string[] { "DFF11", "DFF11", "RFF11", "RFF11", "RFF11", "CFF11" };
var source = value.GroupBy(t => t.Trim()).Select(t => new { count = t.Count(), key = t.Key }).ToArray();
foreach (var s in source)
Console.WriteLine(s.key + ":" + s.count);
var source = value.GroupBy(t => t.Trim()).Select(t => new { count = t.Count(), key = t.Key }).ToArray();
foreach (var s in source)
Console.WriteLine(s.key + ":" + s.count);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询