【发布时间】:2011-10-29 16:20:27
【问题描述】:
假设我有一个相当大的IList<foo>,其中foo 看起来像这样:
public class foo
{
public string Region { get; set; }
public string Territory { get; set; }
public string Location { get; set; }
public string Person { get; set; }
}
...有没有办法,使用相当快速/有效的表达式,将这些 foo 项目按Region“分组”,所以我最终可能会得到一个IDictionary<string, IList<foo>> 并让string 键成为Region 属性,每个从属 IList<foo> 仅包含与该区域匹配的 foo 记录? (它不必是IDictionary,这只是为了说明我正在尝试做的事情的要点。)我想向我的 MVC 视图呈现一个交互式列表,以这种方式组织,而不必写一些东西比较复杂或者使用第三方库。
【问题讨论】:
-
嗯。也许我假设 GroupBy 就像 SQL Group By。这对我来说似乎是不正确的。好吧,我想这就是答案!
标签: c# linq collections generic-programming