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


C# Dictionary.OrderBy方法代码示例

本文整理汇总了C#中System.Collections.Dictionary.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.OrderBy方法的具体用法?C# Dictionary.OrderBy怎么用?C# Dictionary.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Dictionary的用法示例。


在下文中一共展示了Dictionary.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShowParsedCommand

        public static void ShowParsedCommand(ConsoleCommand consoleCommand, TextWriter consoleOut)
        {
            if (!consoleCommand.TraceCommandAfterParse)
            {
                return;
            }

            string[] skippedProperties = new []{
                "Command",
                "OneLineDescription",
                "Options",
                "TraceCommandAfterParse",
                "RemainingArgumentsCount",
                "RemainingArgumentsHelpText",
                "RequiredOptions"
            };

            var properties = consoleCommand.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                .Where(p => !skippedProperties.Contains(p.Name));

            var fields = consoleCommand.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
                .Where(p => !skippedProperties.Contains(p.Name));

            Dictionary<string,string> allValuesToTrace = new Dictionary<string, string>();

            foreach (var property in properties)
            {
                object value = property.GetValue(consoleCommand, new object[0]);
                allValuesToTrace[property.Name] = value != null ? value.ToString() : "null";
            }

            foreach (var field in fields)
            {
                allValuesToTrace[field.Name] = MakeObjectReadable(field.GetValue(consoleCommand));
            }

            consoleOut.WriteLine();

            string introLine = String.Format("Executing {0}", consoleCommand.Command);

            if (string.IsNullOrEmpty(consoleCommand.OneLineDescription))
                introLine = introLine + ":";
            else
                introLine = introLine + " (" + consoleCommand.OneLineDescription + "):";

            consoleOut.WriteLine(introLine);

            foreach(var value in allValuesToTrace.OrderBy(k => k.Key))
                consoleOut.WriteLine("    " + value.Key + " : " + value.Value);

            consoleOut.WriteLine();
        }
开发者ID:diadistis,项目名称:ManyConsole,代码行数:52,代码来源:ConsoleHelp.cs

示例2: Initialize

        public void Initialize(bool blockUnrated)
        {
            if (_ratings != null) return;  //already intitialized

            //We get our ratings from the server
            _ratings = new Dictionary<string, int>();
            try
            {
                foreach (var rating in Kernel.ApiClient.GetParentalRatings())
                {
                    _ratings.Add(rating.Name, rating.Value);
                }
            }
            catch (Exception e)
            {
                Logging.Logger.ReportException("Error retrieving ratings from server",e);
                return;
            }

            try
            {
                _ratings.Add("", blockUnrated ? 1000 : 0);
            }
            catch (Exception e)
            {
                Logging.Logger.ReportException("Error adding blank value to ratings", e);
            }
            //and rating reverse lookup dictionary (non-redundant ones)
            ratingsStrings.Clear();
            int lastLevel = -10;
            ratingsStrings.Add(-1,LocalizedStrings.Instance.GetString("Any"));
            foreach (var pair in _ratings.OrderBy(p => p.Value))
            {
                if (pair.Value > lastLevel)
                {
                    lastLevel = pair.Value;
                    try
                    {
                        ratingsStrings.Add(pair.Value, pair.Key);
                    }
                    catch (Exception e)
                    {
                        Logging.Logger.ReportException("Error adding "+pair.Value+" to ratings strings", e);
                    }
                }
            }

        }
开发者ID:bartonnen,项目名称:MediaBrowser.Classic,代码行数:48,代码来源:Ratings.cs

示例3: GetColumns

        private IEnumerable<string> GetColumns()
        {
            var columns = new Dictionary<int, string>();

            foreach (PropertyInfo propertyInfo in _type.GetProperties())
            {
                var attribute = Attributes.GetAttribute<UserDefinedTableTypeColumnAttribute>(propertyInfo);

                if (attribute != null)
                    columns.Add(attribute.Order, propertyInfo.Name);
            }

            var sortedColumns = columns.OrderBy(kvp => kvp.Key);

            return sortedColumns.Select(kvp => kvp.Value);
        }
开发者ID:rundkaas,项目名称:EntityFrameworkExtras,代码行数:16,代码来源:UserDefinedTableGenerator.cs

示例4: OAuthCalculateAuthHeader

        /// <summary>
        /// Returns the string for the Authorisation header to be used for OAuth authentication.
        /// Parameters other than OAuth ones are ignored.
        /// </summary>
        /// <param name="parameters">OAuth and other parameters.</param>
        /// <returns></returns>
        public static string OAuthCalculateAuthHeader(Dictionary<string, string> parameters)
        {
            StringBuilder sb = new StringBuilder("OAuth ");

            var sorted = parameters.OrderBy(x => x.Key);

            foreach (KeyValuePair<string, string> pair in sorted)
            {
                if (pair.Key.StartsWith("oauth"))
                {
                    sb.Append(pair.Key + "=\"" + Uri.EscapeDataString(pair.Value) + "\",");
                }
            }

            return sb.Remove(sb.Length - 1, 1).ToString();
        }
开发者ID:liquidboy,项目名称:X,代码行数:22,代码来源:TwitterResponder.cs

示例5: GetDistribution

        public override IEnumerable GetDistribution(Release[] releases)
        {
            Dictionary<string, int> result = new Dictionary<string, int>();

            foreach (Release release in releases)
            {
                if (!string.IsNullOrEmpty(release.Country))
                {
                    if (!result.ContainsKey(release.Country))
                    {
                        result[release.Country] = 0;
                    }

                    ++result[release.Country];
                }
            }

            var allItems = result.OrderBy(i => -i.Value);
            var topItems = allItems.Take(6);
            var otherItems = allItems.Skip(6);
            int otherItemsSum = otherItems.Sum(i => i.Value);

            foreach (var topItem in topItems)
            {
                yield return new Item()
                {
                    Key = topItem.Key + " (" + topItem.Value + ")",
                    Value = topItem.Value,
                    Countries = new string[] { topItem.Key },
                };
            }

            if (otherItemsSum != 0)
            {
                yield return new Item()
                {
                    Key = "Other (" + otherItemsSum + ")",
                    Value = otherItemsSum,
                    Countries = otherItems.Select(i => i.Key).ToArray()
                };
            }
        }
开发者ID:karamanolev,项目名称:MusicDatabase,代码行数:42,代码来源:CountryChart.cs

示例6: SortChildren

        public static void SortChildren(this IDomObject node)
        {
            if (node.ChildNodes.Count == 0)
                return;

            var buffer = new Dictionary<string, IDomObject>();

            foreach (var child in node.ChildNodes)
            {
                var value = GetValueBasedOnNode(child);
                if (!string.IsNullOrWhiteSpace(value))
                {
                    buffer.Add(value, child);
                }
            }

            node.ChildNodes.Clear();

            var sorted = buffer.OrderBy(x => x.Key);
            foreach (var kvp in sorted)
            {
                node.ChildNodes.Add(kvp.Value);
            }
        }
开发者ID:robcthegeek,项目名称:CsProjSorter,代码行数:24,代码来源:CsQueryExtensions.cs

示例7: ProcessUniqueTerms

        public static string ProcessUniqueTerms(Index index)
        {
            _index = index;

            // initialize the rank dictionary
            Dictionary<int, double> rank = new Dictionary<int, double>();
            foreach (KeyValuePair<int, string> document in _index.documents)
                rank.Add(document.Key, 0.0);

            // loop though all of the documents in the index
            foreach (KeyValuePair<int, string> document in _index.documents)
            {
                rank[document.Key] = ((double)UniqueTermsCount(document.Value) / _index.GetDocumentLength(document.Key));
            }

            // calculate the results
            StringBuilder sb = new StringBuilder();
            foreach (KeyValuePair<int, double> result in rank.OrderBy(z => z.Value))
            {
                sb.AppendLine(result.Key.ToString() + " " + result.Value.ToString());
            }

            return sb.ToString();
        }
开发者ID:purdue-cs-groups,项目名称:cs490-WIR-project01,代码行数:24,代码来源:WeightHandler.cs

示例8: verifyPopularity

        /// <summary>
        /// Determine popularity of classes for the selection process using the lists
        /// </summary>
        public void verifyPopularity()
        {
            AllClasses = new Dictionary<String, int>();

            ThirdClasses = new Dictionary<String, int>();
            SecondClasses = new Dictionary<String, int>();
            FirstClasses = new Dictionary<String, int>();

            foreach(Presenter currentPresenter in presenterList)
            {
                AllClasses.Add(currentPresenter.PresenterTitle, 0);

                #region Loop over all requests and populate dictionaries
                foreach (Request currentRequest in requestList)
                {
                    string presenterName = currentPresenter.PresenterTitle;
                    if (currentRequest.RequestOne.Equals(presenterName) || currentRequest.RequestTwo.Equals(presenterName) || currentRequest.RequestThree.Equals(presenterName) || currentRequest.RequestFour.Equals(presenterName) || currentRequest.RequestFive.Equals(presenterName))
                    {
                        if (AllClasses.ContainsKey(presenterName))
                        {
                            int currentCount = AllClasses[presenterName];
                            ++currentCount;
                            AllClasses[presenterName] = currentCount;
                        }
                        else
                        {
                            AllClasses.Add(presenterName, 1);
                        }
                    }

                    if (currentRequest.RequestThree.Equals(presenterName) )
                    {
                        if (ThirdClasses.ContainsKey(presenterName))
                        {
                            int currentCount = ThirdClasses[presenterName];
                            ++currentCount;
                            ThirdClasses[presenterName] = currentCount;
                        }
                        else
                        {
                            ThirdClasses.Add(presenterName, 1);
                        }
                    }

                    if (currentRequest.RequestTwo.Equals(presenterName) )
                    {
                        if (SecondClasses.ContainsKey(presenterName))
                        {
                            int currentCount = SecondClasses[presenterName];
                            ++currentCount;
                            SecondClasses[presenterName] = currentCount;
                        }
                        else
                        {
                            SecondClasses.Add(presenterName, 1);
                        }
                    }

                    if (currentRequest.RequestOne.Equals(presenterName))
                    {
                        if (FirstClasses.ContainsKey(presenterName))
                        {
                            int currentCount = FirstClasses[presenterName];
                            ++currentCount;
                            FirstClasses[presenterName] = currentCount;
                        }
                        else
                        {
                            FirstClasses.Add(presenterName, 1);
                        }
                    }
                }
            #endregion
            }

            AllClasses = AllClasses.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
            ThirdClasses = ThirdClasses.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
            SecondClasses = SecondClasses.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
            FirstClasses = FirstClasses.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        }
开发者ID:CodyHenrichsen-CTEC,项目名称:DPMS_No_Options,代码行数:83,代码来源:WorkshopData.cs

示例9: WriteDicionaryBase

        private void WriteDicionaryBase(object input)
        {
            int count = ((DictionaryBase) input).Count;
            WritePrimativeObject(count, typeof(int));
            IDictionaryEnumerator dicEnum = (input as DictionaryBase).GetEnumerator();
            var keyValList = new Dictionary<object, object>();

            while (dicEnum.MoveNext())
            {
                keyValList[dicEnum.Key] = dicEnum.Value;
            }

            var query = keyValList.OrderBy(keyVal => keyVal.Key.ToString());
            foreach (KeyValuePair<object, object> keyValuePair in query)
            {
                WriteObject(keyValuePair.Key);
                WriteObject(keyValuePair.Value);
            }

            //while (dicEnum.MoveNext())
            //{
            //    WriteObject(dicEnum.Key);
            //    WriteObject(dicEnum.Value);
            //}

            // Custom fields
            WriteCustomFields(input);
        }
开发者ID:herohut,项目名称:elab,代码行数:28,代码来源:RawDataWriter.cs

示例10: solidLoad

        private void solidLoad(Info n)
        {


            Dictionary<string, int> keycache = new Dictionary<string, int>();
            SpecialBitmap jz;
            getAngleMap(n, jz = new SpecialBitmap(dir2 + "plane solid ang 1.png"), keycache, 1);
            getAngleMap(n, jz = new SpecialBitmap(dir2 + "plane solid ang 2.png"), keycache, 2);

            getHightMap(n, jz = new SpecialBitmap(dir2 + "plane solid n 1.png"), keycache, 1);
            getHightMap(n, jz = new SpecialBitmap(dir2 + "plane solid n 2.png"), keycache, 2);



            n.HeightMaps = keycache.OrderBy(a => a.Value).Select(a => a.Key).ToArray();

        }
开发者ID:OurSonic,项目名称:Sonic-Image-Parser,代码行数:17,代码来源:ChunkConsumer.cs

示例11: DescribeSchema


//.........这里部分代码省略.........
            base64Property.Type = typeof(System.String).ToString();
            base64Property.SoType = SoType.Memo;

            pdfServiceObject.Properties.Add(base64Property);

            // for update - return path
            Property returnpathProperty = new Property();
            returnpathProperty.Name = "returnpath";
            returnpathProperty.MetaData.DisplayName = "Return Path";
            returnpathProperty.Type = typeof(System.String).ToString();
            returnpathProperty.SoType = SoType.Text;

            pdfServiceObject.Properties.Add(returnpathProperty);

            Type type = typeof(PDFInfo);
            PropertyInfo[] props = type.GetProperties();
            foreach (var p in props)
            {
                //text += docinfo.GetType().GetProperty(field.Name).GetValue(docinfo, null);

                Property infoproperty = new Property();
                infoproperty.Name = p.Name;
                infoproperty.MetaData.DisplayName = p.Name;
                infoproperty.Type = p.PropertyType.ToString();

                // needs to be mapped properly
                infoproperty.SoType = SoType.Text;

                pdfServiceObject.Properties.Add(infoproperty);
                allmetadata.Add(infoproperty);
                allprops.Add(infoproperty);
            }

            foreach (KeyValuePair<string, PDFField> field in fields.OrderBy(p => p.Key))
            {
                Property property = new Property();
                property.Name = field.Value.FullName.Replace(" ", "_");
                property.MetaData.DisplayName = field.Value.FullName;
                property.Type = typeof(System.String).ToString();
                property.SoType = SoType.Text;
                property.MetaData.ServiceProperties.Add("pdffullname", field.Value.FullName);
                property.MetaData.ServiceProperties.Add("pdfalternativename", field.Value.AlternativeName);
                property.MetaData.ServiceProperties.Add("pdfisreadonly", field.Value.IsReadOnly);
                property.MetaData.ServiceProperties.Add("pdfisrequired", field.Value.IsRequired);
                property.MetaData.ServiceProperties.Add("pdfpartialname", field.Value.PartialName);
                property.MetaData.ServiceProperties.Add("pdftype", field.Value.Type);

                allfields.Add(property);
                allprops.Add(property);
                pdfServiceObject.Properties.Add(property);
            }

            // add methods
            Method GetAllFieldValues = new Method();
            GetAllFieldValues.Name = "getallfieldvalues";
            GetAllFieldValues.MetaData.DisplayName = "Get All Field Values";
            GetAllFieldValues.Type = SourceCode.SmartObjects.Services.ServiceSDK.Types.MethodType.Read;

            GetAllFieldValues.InputProperties.Add(inputUriproperty);
            GetAllFieldValues.Validation.RequiredProperties.Add(inputUriproperty);

            GetAllFieldValues.ReturnProperties.Add(inputUriproperty);
            foreach (Property prop in allprops)
            {
                GetAllFieldValues.ReturnProperties.Add(prop);
            }
开发者ID:jonnoking,项目名称:K2-PDF-Form-Brokers,代码行数:67,代码来源:DataConnector.cs

示例12: reOrderPipeLine

        // print in the order
        private static void reOrderPipeLine(Dictionary<string, int> clusterList, StreamWriter output)
        {
            foreach (var data in clusterList.OrderBy(key => key.Value))
            {
                output.WriteLine(data.Key);

            }
        }
开发者ID:yuanzheng,项目名称:logs-analysis,代码行数:9,代码来源:Program.cs

示例13: Sort

        void Sort(List<MmlResolvedEvent> l)
        {
            var msgBlockByTime = new Dictionary<int,List<MmlResolvedEvent>> ();
            int m = 0;
            int prev = 0;
            while (m < l.Count) {
                var e = l [m];
                List<MmlResolvedEvent> pl;
                if (!msgBlockByTime.TryGetValue (l [m].Tick, out pl)) {
                    pl = new List<MmlResolvedEvent> ();
                    msgBlockByTime.Add (e.Tick, pl);
                }
                for (; m < l.Count; m++) {
                    pl.Add (l [m]);
                    if (m + 1 < l.Count && l [m + 1].Tick != prev)
                        break;
                }
                m++;
            }

            l.Clear ();
            foreach (var sl in msgBlockByTime.OrderBy (kvp => kvp.Key).Select (kvp => kvp.Value))
                l.AddRange (sl);
        }
开发者ID:atsushieno,项目名称:mugene,代码行数:24,代码来源:mml_variable_processor.cs

示例14: GetContainedSearchKeys

 //Return the contained search key
 private string[] GetContainedSearchKeys(string[] searchKeys, string line)
 {
     searchKeys = RemovePartialWords(searchKeys.Where(k => line.IndexOf(k,
         StringComparison.InvariantCultureIgnoreCase) >= 0).ToArray());
     var containedKeys = new Dictionary<String, int>();
     foreach (string key in searchKeys)
     {
         var index = line.IndexOf(key, StringComparison.InvariantCultureIgnoreCase);
         if (index >= 0)
         {
             containedKeys.Add(key, index);
         }
     }
     return containedKeys.OrderBy(p => p.Value).Select(p => p.Key).ToArray();
 }
开发者ID:spati2,项目名称:FSE-2012-SANDO,代码行数:16,代码来源:SearchResultViewModel.cs

示例15: Problem16

 public void Problem16()
 {
     Dictionary<string, double> d = new Dictionary<string,double>();
     int f;
     Console.ReadLineQ<int>(out f, "Fjöldi");
     for (int i = 0; i < f; i++)
     {
         string n;
         double h, t;
         Console.ReadLineQ(out n, "Nafn " + (i + 1)).ReadLineQ<double>(out h, "Hæð " + (i + 1)).ReadLineQ<double>(out t, "Þyngd " + (i + 1));
         Console.WriteLine("\n");
         d.Add(n, t / Math.Pow(h, 2));
     }
     foreach (var i in d.OrderBy(x => x.Value))
     {
         Console.WriteLine("{0} {1:0.#}" ,i.Key, i.Value);
     }
 }
开发者ID:jamiees2,项目名称:FK2013_DELTA,代码行数:18,代码来源:FyrirH2013ScottyHringurHlynur.cs


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