var duplicates =
from word in words
group word.ToUpper() by word.ToUpper() into g
where g.Count() > 1
select new { g.Key, Count = g.Count() };
new { g.Key, Count = g.Count() };这个是什么意思?
from word in words
group word.ToUpper() by word.ToUpper() into g
where g.Count() > 1
select new { g.Key, Count = g.Count() };
new { g.Key, Count = g.Count() };这个是什么意思?
感觉你的代码有问题,应该是:
new { Key = g.Key, Count = g.Count() };
这样就是包含Key,Count两个属性的匿名类型.
{
string[] words={"aaccd","AAccd","ccd"};
var duplicates =
from word in words
group word.ToUpper() by word.ToUpper() into g
where g.Count() > 1
select new { g.Key, Count = g.Count() }; foreach(var w in duplicates)
{
Console.WriteLine(w.Key +" "+w.Count);
}
}
/*
结果:
AACCD 2
*/
感觉你的代码有问题,应该是:
new { Key = g.Key, Count = g.Count() };
这样就是包含Key,Count两个属性的匿名类型.