我有一個String數組,還挺像這樣:LINQ查詢GROUP BY和選擇第一項
// icon, category, tool
String[,] subButtonData = new String[,]
{
{"graphics/gui/brushsizeplus_icon", "Draw", "DrawBrushPlus"},
{"graphics/gui/brushsizeminus_icon", "Draw", "DrawBrushMinus"},
{"graphics/gui/freedraw_icon", "Draw", "DrawFree"},
{"graphics/gui/linedraw_icon", "Draw", "DrawLine"},
{"graphics/gui/rectangledraw_icon", "Draw", "DrawRectangle"},
{"graphics/gui/ellipsedraw_icon", "Draw", "DrawEllipse"},
{"graphics/gui/brushsizeplus_icon", "Brusher", "BrusherBrushPlus"},
{"graphics/gui/brushsizeminus_icon", "Brusher", "BrusherBrushMinus"},
{"graphics/gui/brushsizeplus_icon", "Text", "TextBrushPlus"},
{"graphics/gui/brushsizeminus_icon", "Text", "TextBrushMinus"},
};
然後我填充List<Button>
我叫mainButtons
按鈕鍵入這是我的查詢進行分組Category
:
var categories = from b in mainButtons
group b by b.category into g
select new { Category = g.Key, Buttons = g };
如何在我的主列表中選擇每個組的第一個項目? (沒有迭代每個並添加到另一個列表?)
爲什麼您的查詢使用與樣本集合不同的東西? – svick