日期:2014-05-16 浏览次数:21134 次
void Main()
{
var list1=new List<demo>
{
new demo{NO="A",Time="2014-03-27"},
new demo{NO="B",Time="2014-03-28"},
new demo{NO="C",Time="2014-03-29"},
};
var list2=new List<demo>
{
new demo{NO="B",Time="2014-09-09"},
new demo{NO="D",Time="2014-08-08"},
};
var result=list1.Concat(list2).GroupBy(l=>l.NO)
.Select(g=>new demo{ NO=g.Key,Time=g.Count()==1?g.First().Time+"-\"\"":string.Join("-",g.Select(x=>x.Time).ToArray())});
}
class demo
{
public string NO{get;set;}
public string Time{get;set;}
}