我有一个datatable集合 用linq 怎么通过其中的二列得到该二列重复的所有数据
2个回答
展开全部
class Group
{
public String name;
public String code;
public String phone;
public String id;
}
class RepeatGroup
{
public String code;
public String id;
public List<Group> Groups;
public RepeatGroup(String c,String i)
{
code=c;
id=i;
Groups=new List<Group>();
}
}
List<RepeatGroup> GetRepeat(List<Group> groups)
{
List<RepeatGroup> repeats=new List<RepeatGroup>();
for(int i=0;i<groups.Count;i++)
{
if(repeats.Count(q=>q.id==groups[i].id&&q.code==groups[i].code)==0)
{
RepeatGroup temp=new RepeatGroup(groups[i].code,groups[i].id);
temp.Groups.Add(groups[i]);
repeats.Add(temp);
}
else
{
repeats.First(q=>q.id==groups[i].id&&q.code==groups[i].code).Groups.Add(groups[i]);
}
}
return repeats.Where(q=>q.Groups.Count>1).ToList();
}
找出重复的,按组排列
{
public String name;
public String code;
public String phone;
public String id;
}
class RepeatGroup
{
public String code;
public String id;
public List<Group> Groups;
public RepeatGroup(String c,String i)
{
code=c;
id=i;
Groups=new List<Group>();
}
}
List<RepeatGroup> GetRepeat(List<Group> groups)
{
List<RepeatGroup> repeats=new List<RepeatGroup>();
for(int i=0;i<groups.Count;i++)
{
if(repeats.Count(q=>q.id==groups[i].id&&q.code==groups[i].code)==0)
{
RepeatGroup temp=new RepeatGroup(groups[i].code,groups[i].id);
temp.Groups.Add(groups[i]);
repeats.Add(temp);
}
else
{
repeats.First(q=>q.id==groups[i].id&&q.code==groups[i].code).Groups.Add(groups[i]);
}
}
return repeats.Where(q=>q.Groups.Count>1).ToList();
}
找出重复的,按组排列
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询