我这里以用的是list,别的类型都差不多一样。。
(测试数据自己添加)
第一种
List<string> AllList = new List<string>();
var q = from p in AllList group p by p into g select new { Key = g.Count(), BranchName = g.Key };
foreach (var v in q)
Console.WriteLine("--" + v.BranchName.ToString() + "--" + v.Key.ToString());
第二种
List<string> AllList = new List<string>();
var q1 = from p in AllBranchList group p by new { g = p } into g select new { Key = g.Count(), BranchName = g.FirstOrDefault() };
foreach (var v in q1)
Console.WriteLine("==" + v.BranchName.ToString() + "--" + v.Key.ToString());