Linq Group按或唯一 [英] Linq GroupBy or Unique
本文介绍了Linq Group按或唯一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮帮我.
我有一个包含多列的列表.
我的要求是获取所有列按单个列分组的列表.
例如:
Please help me out.
I have a list with multiple columns.
my requirement is to get a list with all the columns group by single column.
Ex:
class SearchList
{
string ComposerName;
string MemberID;
string Value1;
String IteamName;
}
List<searchlist> sl=new List<searchlist>
上面的"sl"包含多个项目,从中我想使用linq通过ComposerName获得MemberID,ComposerName,IteamName组.
请给我建议这个
above "sl" contains multiple items, from that i want to get MemberID, ComposerName, IteamName group by ComposerName using linq.
pleas suggest me code for this
推荐答案
的代码我假设您有一个Class类型的列表,如
I assume that you have a list of your Class type like
List<SearchList> searchList = new List<SearchList>();
为了通过分组数据获得所需的结果集,请尝试以下代码
And for getting the desired result set by grouping the data try the below code
var groupedList = from entry in searchList
group entry by new { entry.ComposerName } into grouping
select new
{
ComposerName = grouping.Key.ComposerName,
MemberID = grouping.First().MemberID,
Value1 = grouping.First().Value1,
IteamName = grouping.First().IteamName,
};
希望这可以帮助.如有任何问题,请回来.
Hope this helps. Please get back if you have any issue.
这篇关于Linq Group按或唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文