-6
我有這樣的代碼爲C#C#:循環或數組
var wordCounts1 = myInterface.GetWordCounts(new[] {
"one", "one", "two", "three", "three",});
預期的輸出應該是:
{"one", 2}, {"two", 1}, {"three",2}
我應該怎麼用得到這個輸出迴路或數組?
我有這樣的代碼爲C#C#:循環或數組
var wordCounts1 = myInterface.GetWordCounts(new[] {
"one", "one", "two", "three", "three",});
預期的輸出應該是:
{"one", 2}, {"two", 1}, {"three",2}
我應該怎麼用得到這個輸出迴路或數組?
分組由字應努力
new[] { "one", "one", "two", "three", "three" }
.GroupBy(x => x)
.Select(x => new
{
Word = x.Key,
Count = x.Count()
});
你已經有一個數組。使用循環! – Sinatr
嘗試'GroupBy'和'Count' – slawekwin
如果您需要在數組中使用LINQ –