2 回答

TA贡献1817条经验 获得超6个赞
反转Dictionarys 并计算遇到的每个问题,然后可以使用 LINQ 找出最重要的 3 个问题:
var FAQfor3Months = new Dictionary<string, int>();
var FAQfor4to12Months = new Dictionary<string, int>();
var FAQfor12plusMonths = new Dictionary<string, int>();
foreach (Activity call in CallsForProperty) {
if ( /*call is in 3 months*/ ) {
//do some unrelated stuff
FAQfor3Months.TryGetValue(call.callQuestion, out int count);
FAQfor3Months[call.callQuestion] = count+1;
}
}
var top3ThreeMonthFaqs = FAQfor3Months.OrderByDescending(kvp => kvp.Value).Take(3).Select(kvp => kvp.Key).ToList();

TA贡献1803条经验 获得超3个赞
您的代码将返回组,而不是实际的问题。尝试这个:
var threeMonthFaqs = FAQfor3Months.Values .GroupBy(q => q) .OrderByDescending(g => g.Count()) .SelectMany(g => g) .Distinct() .Take(3);
- 2 回答
- 0 关注
- 120 浏览
添加回答
举报