本文整理汇总了C#中IDictionary.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# IDictionary.OrderByDescending方法的具体用法?C# IDictionary.OrderByDescending怎么用?C# IDictionary.OrderByDescending使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDictionary
的用法示例。
在下文中一共展示了IDictionary.OrderByDescending方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNearestLevel
public static string GetNearestLevel(IDictionary<string, Resolution> resolutions, double resolution)
{
if (resolutions.Count == 0)
{
throw new ArgumentException("No tile resolutions");
}
var localResolutions = resolutions.OrderByDescending(r => r.Value.UnitsPerPixel);
//smaller than smallest
if (localResolutions.Last().Value.UnitsPerPixel > resolution) return localResolutions.Last().Key;
//bigger than biggest
if (localResolutions.First().Value.UnitsPerPixel < resolution) return localResolutions.First().Key;
string result = null;
double resultDistance = double.MaxValue;
foreach (var current in localResolutions)
{
double distance = Math.Abs(current.Value.UnitsPerPixel - resolution);
if (distance < resultDistance)
{
result = current.Key;
resultDistance = distance;
}
}
if (result == null) throw new Exception("Unexpected error when calculating nearest level");
return result;
}
示例2: PopulateListView
private void PopulateListView(IDictionary<char, int> characterCollection)
{
foreach(var item in characterCollection.OrderByDescending(kp => kp.Value))
{
ListViewItem lvi = new ListViewItem(item.Key.ToString());
lvi.SubItems.Add(item.Value.ToString());
CharacterUsageListView.Items.Add(lvi);
}
}
示例3: SubstituteVariables
protected string[] SubstituteVariables(IDictionary<string, string> vars, string[] args)
{
foreach (var item in vars.OrderByDescending(x => x.Key.Length))
{
for (int i = 0; i < args.Length; i++)
{
args[i] = args[i].Replace(item.Key, item.Value);
}
}
return args;
}
示例4: ScoreScene
public ScoreScene(
Game game,
SpriteFont font,
IDictionary<int, string> highScores,
Texture2D background,
params Tuple<int, IController>[] playerScores)
: base(game)
{
var backgroundComponent = new ImageComponent(game, background, ImageComponent.DrawMode.Center);
Components.Add(backgroundComponent);
if (highScores.Count < 10 || playerScores.Any(ps => highScores.Keys.Any(k => k < ps.Item1)))
{
AcceptingInput = true;
var highCount = playerScores.Count(ps => highScores.Keys.Any(k => k < ps.Item1));
var remove = _highScores.Keys.OrderBy(k => k).Take(highCount);
foreach (var r in remove)
{
_highScores.Remove(r);
}
_playerEntries =
playerScores.OrderByDescending(ps => ps.Item1)
.Take(highCount)
.Select(ps => Tuple.Create(ps.Item1, ps.Item2, string.Empty))
.ToList();
foreach (var pe in _playerEntries)
{
highScores.Add(pe.Item1, pe.Item3);
}
}
var y = 100;
foreach (var hs in highScores.OrderByDescending(x => x.Key))
{
var component = new TextComponent(game, font, new Vector2(100, y), Color.White)
{
Visible = true,
Enabled = true,
Text = hs.Value + " " + hs.Key
};
var playerScore = playerScores.LastOrDefault(ps => hs.Key == ps.Item1);
var controller = playerScore != null ? playerScore.Item2 : null;
Components.Add(component);
_highScores.Add(hs.Key, Tuple.Create(string.Empty, component, controller));
y += 100;
}
}
示例5: LevelOverrideMap
public LevelOverrideMap(
IDictionary<string, LoggingLevelSwitch> overrides,
LogEventLevel defaultMinimumLevel,
LoggingLevelSwitch defaultLevelSwitch)
{
if (overrides == null) throw new ArgumentNullException(nameof(overrides));
_defaultLevelSwitch = defaultLevelSwitch;
_defaultMinimumLevel = defaultLevelSwitch != null ? LevelAlias.Minimum : defaultMinimumLevel;
// Descending order means that if we have a match, we're sure about it being the most specific.
_overrides = overrides
.OrderByDescending(o => o.Key)
.Select(o => new LevelOverride(o.Key, o.Value))
.ToArray();
}
示例6: GenerateReport
static void GenerateReport(IDictionary<Uri, long> dump, IDictionary<string, long> errors)
{
var totalCount = dump.Sum(pair => pair.Value);
var distinctCount = dump.Count;
var errorCount = errors.Sum(pair => pair.Value);
var top10 = dump.OrderByDescending(pair => pair.Value).Take(10).ToList();
var top10Errors = errors.OrderByDescending(pair => pair.Value).Take(10).ToList();
Console.Clear();
Console.WriteLine($"Total Count:\t\t{totalCount}");
Console.WriteLine($"Distinct Count:\t\t{distinctCount}");
Console.WriteLine($"Error Count:\t\t{errorCount}");
Console.WriteLine();
Console.WriteLine("Top 10:");
top10.ForEach(pair => Console.WriteLine($" ({pair.Value}) {pair.Key}"));Console.WriteLine();
Console.WriteLine("Top 10 Errors:");
top10Errors.ForEach(pair => Console.WriteLine($" ({pair.Value}) {pair.Key}"));
}
示例7: DoesReflectedSimplexPass
public bool DoesReflectedSimplexPass(Func<IVertex, double> getObjectiveMeasure, Func<StandardKernel, int, IVertex> getAverageOfAllButWorstVertices,
Func<StandardKernel, IVertex, IVertex, double, IVertex> getAlteredVertex, IDictionary<int, double> objectiveMeasures)
{
var numParams = CurrentSimplex.Vertices.Count - 1;
ISimplex reflectedSimplex = CurrentSimplex.GetAsCopy();
var firstWorstValueAsKey = objectiveMeasures.OrderByDescending(e => e.Value).ToList()[0].Key;
IVertex worstVertex = reflectedSimplex.Vertices[firstWorstValueAsKey];
var secondWorstValueAsKey = objectiveMeasures.OrderByDescending(e => e.Value).ToList()[1].Key;
var bestValueAsKey = objectiveMeasures.OrderByDescending(e => e.Value).ToList()[numParams].Key;
var kernel = NinJectBindings.GetBoundKernel();
IVertex avgVertex = getAverageOfAllButWorstVertices(kernel, firstWorstValueAsKey);
var reflectedVertex = getAlteredVertex(kernel, avgVertex, worstVertex, AlphaReflection);
var reflectedVertexObjMeasure = getObjectiveMeasure(reflectedVertex);
if (reflectedVertexObjMeasure >= objectiveMeasures[secondWorstValueAsKey])
{
return false;
}
if (reflectedVertexObjMeasure >= objectiveMeasures[bestValueAsKey] && reflectedVertexObjMeasure < objectiveMeasures[secondWorstValueAsKey])
{
AssignVertexToCurrentSimplex(numParams, reflectedSimplex, firstWorstValueAsKey, reflectedVertex);
objectiveMeasures[firstWorstValueAsKey] = reflectedVertexObjMeasure;
return true;
}
var expandedVertex = getAlteredVertex(kernel, avgVertex, worstVertex, GammaReflectionExpansion);
var expandedVertexObjMeasure = getObjectiveMeasure(expandedVertex);
if (expandedVertexObjMeasure < reflectedVertexObjMeasure)
{
AssignVertexToCurrentSimplex(numParams, reflectedSimplex, firstWorstValueAsKey, expandedVertex);
objectiveMeasures[firstWorstValueAsKey] = expandedVertexObjMeasure;
return true;
}
AssignVertexToCurrentSimplex(numParams, reflectedSimplex, firstWorstValueAsKey, reflectedVertex);
objectiveMeasures[firstWorstValueAsKey] = reflectedVertexObjMeasure;
return true;
}
示例8: DoesContractedSimplexPass
public bool DoesContractedSimplexPass(Func<IVertex, double> getObjectiveMeasure, Func<StandardKernel, int, IVertex> getAverageOfAllButWorstVertices,
Func<StandardKernel, IVertex, IVertex, double, IVertex> getAlteredVertex, IDictionary<int,double> objectiveMeasures )
{
var numParams = CurrentSimplex.Vertices.Count - 1;
ISimplex contractedSimplex = CurrentSimplex.GetAsCopy();
var firstWorstValueAsKey = objectiveMeasures.OrderByDescending(e => e.Value).ToList()[0].Key;
IVertex worstVertex = contractedSimplex.Vertices[firstWorstValueAsKey];
var kernel = NinJectBindings.GetBoundKernel();
IVertex avgVertex = getAverageOfAllButWorstVertices(kernel, firstWorstValueAsKey);
var contractedVertex = getAlteredVertex(kernel, avgVertex, worstVertex, RhoContraction);
var contractedVertexObjMeasure = getObjectiveMeasure(contractedVertex);
if (contractedVertexObjMeasure >= objectiveMeasures[firstWorstValueAsKey])
{
return false;
}
AssignVertexToCurrentSimplex(numParams, contractedSimplex, firstWorstValueAsKey, contractedVertex);
objectiveMeasures[firstWorstValueAsKey] = contractedVertexObjMeasure;
return true;
}
示例9: Balance
/// <summary>
/// Initializes a new instance of <see cref="Balance"/> class
/// </summary>
/// <param name="money">dictionary with denomination as keys and amount as values</param>
public Balance(IDictionary<decimal, int> money)
{
_money = money.OrderByDescending(pair => pair.Key)
.ToDictionary(pair => pair.Key, pair => pair.Value);
}
示例10: GetPagesRecursive
private void GetPagesRecursive(HtmlAgilityPack.HtmlNode document, IDictionary<int, string> pages)
{
var chapterPages = document.SelectNodes(@"//div[@class=""main-body""]//div[@class=""btn-group""][2]/ul[@class=""dropdown-menu""]/li/a");
if (chapterPages == null)
{
throw new ParserException("Could not find expected elements on website.", document.InnerHtml);
}
int addedCount = 0;
foreach (var pageLink in chapterPages)
{
int pageNumber = 0;
var url = GetFullUrl(pageLink.Attributes["href"].Value);
if (pages.Any(kvp => kvp.Value == url)) // skip duplicate urls
continue;
if (!Int32.TryParse(Regex.Match(pageLink.InnerText, @"\d+").Value, out pageNumber))
_log.Error("Unable to parse page number '" + pageLink.InnerText + "'");
if (pages.ContainsKey(pageNumber)) // if page is already in dictionary use random number instead
pageNumber = Random;
pages.Add(pageNumber, url);
addedCount++;
}
if (addedCount > 0)
{
var pageRecord = pages.OrderByDescending(kvp => kvp.Key).Skip(1).FirstOrDefault();
if (pageRecord.Equals(default(KeyValuePair<int, string>)))
return;
var nextDocument = WebHelper.GetHtmlDocument(pageRecord.Value);
GetPagesRecursive(nextDocument, pages);
}
}
示例11: GetMostRepresentativeNumberOfTouchPoints
private static Option<int> GetMostRepresentativeNumberOfTouchPoints(IDictionary<int, int> touchRegistry)
{
if (touchRegistry.Any())
{
var touchesOrderedByAppearance = touchRegistry.OrderByDescending(pair => pair.Value);
return Option.Full(touchesOrderedByAppearance.First().Key);
}
return Option.Empty();
}