我的列表包括名为“ID”、“名称”和“类别”的类。列表中有 6 项。
List<MyData> list =
{
{0, "John", "Police"},
{1,"Michael", "Police"},
{2,"Alice", "Police"},
{3, "Ferdinand", "Thief"},
{4, "Jocas", "Thief"},
{5, "Connor", "Thief"}
};
我想用 LINQ 按“类别”列出每组数量有限的它们。
示例:我想为每个“类别”列出 2 个项目。列出应如下:
John Police
Michael Police
Ferdinand Thief
Jocas Thief