当前位置: 首页>>代码示例>>C#>>正文


C# IDictionary.OrderByDescending方法代码示例

本文整理汇总了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;
        }
开发者ID:smileliaohua,项目名称:TrafficSpider,代码行数:29,代码来源:Utilities.cs

示例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);
            }
        }
开发者ID:BarryBurke,项目名称:GrosvenorTest,代码行数:10,代码来源:CharacterUsageFormView.cs

示例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;
 }
开发者ID:ambf1435,项目名称:Seas0nPass-Windows,代码行数:11,代码来源:PatchCommand.cs

示例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;
            }
        }
开发者ID:ImaginaryDevelopment,项目名称:RockRainEnhanced,代码行数:50,代码来源:ScoreScene.cs

示例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();
        }
开发者ID:serilog,项目名称:serilog,代码行数:15,代码来源:LevelOverrideMap.cs

示例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}"));
        }
开发者ID:LarsVonQualen,项目名称:DumbCrawler,代码行数:19,代码来源:Program.cs

示例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;
        }
开发者ID:rupertswasey,项目名称:DownHillSimplex,代码行数:40,代码来源:DownHillSimplex.cs

示例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;
        }
开发者ID:rupertswasey,项目名称:DownHillSimplex,代码行数:21,代码来源:DownHillSimplex.cs

示例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);
 }
开发者ID:Bazaleev,项目名称:VendingMachine,代码行数:9,代码来源:ChangeCalculator.cs

示例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);
            }
        }
开发者ID:blacker-cz,项目名称:MangaScraper,代码行数:39,代码来源:MangaStream.cs

示例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();
 }
开发者ID:CharlesKwon,项目名称:wpfgesturerecognizer,代码行数:9,代码来源:RecognitionCentral.cs


注:本文中的IDictionary.OrderByDescending方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。