本文整理汇总了C#中BLL.Dictionary.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.OrderByDescending方法的具体用法?C# Dictionary.OrderByDescending怎么用?C# Dictionary.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BLL.Dictionary
的用法示例。
在下文中一共展示了Dictionary.OrderByDescending方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetReport
public string GetReport(Portfolio portfolio, IEnumerable<Category> categories, IEnumerable<CategoryWeight> weights)
{
var reportBuilder = new StringBuilder();
var quotes = GetQuotes(portfolio);
var valuesDict = CalculateValues(portfolio, quotes);
var weightsList = weights.ToList();
//DebugPrint(reportBuilder, valuesDict);
var total = valuesDict.Values.Where(v => v > 0M).Sum();
reportBuilder.AppendLine(string.Format("Portfolio: {0}", portfolio.Name));
foreach (var category in categories)
{
Dictionary<string, decimal> calculations = new Dictionary<string, decimal>();
foreach (var kvpair in valuesDict)
{
var weight = weightsList.Single(w => w.Security.Symbol.Equals(kvpair.Key) && w.Value.Category == category);
if (calculations.ContainsKey(weight.Value.Name))
calculations[weight.Value.Name] += kvpair.Value;
else
calculations.Add(weight.Value.Name, kvpair.Value);
}
reportBuilder.AppendLine(string.Format("\r\n{0}", category.Name));
foreach (var kvpair in calculations.OrderByDescending(kv => kv.Value))
{
reportBuilder.AppendLine(String.Format("{0}: {1:N1}%", kvpair.Key, kvpair.Value / total * 100M));
}
}
return reportBuilder.ToString();
}