-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 –