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


C# SortedList.OrderBy方法代码示例

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


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

示例1: Main

 static void Main()
 {
     Dictionary<string, int> positionDictionary = new Dictionary<string, int>();
     SortedList<string, int> employeeDictionary = new SortedList<string, int>();
     int positionNumber = int.Parse(Console.ReadLine());
     string[] positions = new string[positionNumber];
     for (int i = 0; i < positionNumber; i++)
     {
         positions[i] = Console.ReadLine().TrimEnd();
         int dashIndex = positions[i].IndexOf('-');
         positionDictionary.Add(positions[i].Substring(0, dashIndex - 1), int.Parse(positions[i].Substring(dashIndex + 1)));
     }
     int employeesNumber = int.Parse(Console.ReadLine());
     string[] employees = new string[employeesNumber];
     for (int i = 0; i < employees.Length; i++)
     {
         employees[i] = Console.ReadLine();
         int dashIndex = employees[i].IndexOf('-');
         string subString = employees[i].Substring(dashIndex + 2);
         if (positionDictionary.ContainsKey(subString))
         {
             int value = positionDictionary[subString];
             employeeDictionary.Add(employees[i].Substring(0, dashIndex - 1), value);
         }
     }
     foreach (KeyValuePair<string, int> pair in employeeDictionary.OrderBy(key => key.Value))
     {
         Console.WriteLine(pair.Key);
     }
 }
开发者ID:NasC0,项目名称:Telerik_Homework,代码行数:30,代码来源:Employees.cs

示例2: CalculateNextHands

        public static List<KeyValuePair<string, int>> CalculateNextHands(List<Card> deck, List<Card> hand)
        {
            var allResults = new SortedList<string, int>();

            foreach (var item in deck)
            {
                hand.Add(item);
                string strength = GetBestHand(hand);
                if (!allResults.ContainsKey(strength)) { allResults.Add(strength, 1); }
                else { allResults[strength] += 1; }
                hand.Remove(item);
            }

            var sortedResults = allResults.OrderBy(lam => lam.Value).ToList();
            return sortedResults;
        }
开发者ID:Velair,项目名称:Implicit-Odds-Calculator,代码行数:16,代码来源:Hand.cs

示例3: FindSim

 public List<KeyValuePair<int, Quest>> FindSim(Quest target, IList<Quest> questList)
 {
     var result=new SortedList<int, Quest>();
     questList.All(quest =>
     {
         var value = GetSimValue(target, quest);
         if (value == Int32.MaxValue)
             return true;
         while (result.ContainsKey(value) == true)
             value += 1;
         result.Add(value, quest);
         if (value == Int32.MinValue)
             return false;
         return true;
     });
     return result.OrderBy(x => x.Key).Take(10).ToList();
 }
开发者ID:hefangshi,项目名称:dolmap-data,代码行数:17,代码来源:SimQuestFinder.cs

示例4: Form1

        public Form1()
        {
            InitializeComponent();
            this.mnuCarga.Click += (object sender, EventArgs e) => {
                //para que cerre o recurso
                lstAlumnos.Items.Clear();
                try
                {
                    using (StreamReader stLee = new StreamReader("../../recursos/Alumnos.txt"))
                        while (!stLee.EndOfStream)
                        {
                            lstAlumnos.Items.Add(stLee.ReadLine());
                        }
                }
                catch (FileNotFoundException ex)
                {
                    MessageBox.Show("Non existe o arquivo a ler","Erro",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
            };

            //o igual que en java as lambdas infiren os tipos dos argumentos segundo o contexto
            this.mnuGraba.Click += (sender,  e) => {
                using (StreamWriter strW = new StreamWriter("../../recursos/Escrutinio.txt")) {
                    if (lstVotados.Items.Count!=0)
                    {
                        foreach (var val in lstVotados.Items)
                        {
                            int indice = lstVotados.FindStringExact(val.ToString());
                            strW.WriteLine(string.Format("{0}|{1}", lstVotados.Items[indice], lstVotos.Items[indice]));
                        }
                        MessageBox.Show("Datos gardados con exito", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (MessageBox.Show("Non hai datos\nqueres gardar igual?", "informacion", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) {
                            strW.WriteLine();
                        }

                    }
                }
            };
            this.mnuSalir.Click += (sender, e) => {
                this.Close();
            };
            this.mnuOrdena.Click += (sender, e) => {
                if (lstVotados.Items.Count != 0)
                {
                    SortedList<string, int> valores = new SortedList<string, int>();

                    foreach (var val in lstVotados.Items)
                    {
                        int indice = lstVotados.FindStringExact(val.ToString());
                        valores.Add(lstVotados.Items[indice].ToString(), int.Parse(lstVotos.Items[indice].ToString()));
                    }
                    lstVotados.Items.Clear();
                    lstVotos.Items.Clear();
                    foreach (var v in valores.OrderBy(x => -x.Value))
                    {
                        lstVotados.Items.Add(v.Key);
                        lstVotos.Items.Add(v.Value);
                    }
                    txtNomeDelegado.Text = lstVotados.Items[0].ToString();
                    txtVotosDelegado.Text = lstVotos.Items[0].ToString();
                    txtNomeSubdele.Text = lstVotados.Items[1].ToString();
                    txtVotosSubdele.Text = lstVotos.Items[1].ToString();
                }
                else
                {
                    MessageBox.Show("Non hai datos para ordenar","Informacion",MessageBoxButtons.OK,MessageBoxIcon.Information);
                }
            };
            this.btnOrdena.Click += (sender, e) => {
                if (lstVotados.Items.Count != 0)
                {
                    //a key é o nome xa que non habera duplicados
                    SortedList<string, int> valores = new SortedList<string, int>();

                    foreach (var val in lstVotados.Items)
                    {
                        int indice = lstVotados.FindStringExact(val.ToString());
                        valores.Add(lstVotados.Items[indice].ToString(), int.Parse(lstVotos.Items[indice].ToString()));

                    }
                    lstVotados.Items.Clear();
                    lstVotos.Items.Clear();
                    foreach (var v in valores.OrderBy(x => -x.Value))
                    {
                        lstVotados.Items.Add(v.Key);
                        lstVotos.Items.Add(v.Value);
                    }
                    txtNomeDelegado.Text = lstVotados.Items[0].ToString();
                    txtVotosDelegado.Text = lstVotos.Items[0].ToString();
                    txtNomeSubdele.Text = lstVotados.Items[1].ToString();
                    txtVotosSubdele.Text = lstVotos.Items[1].ToString();
                }
                else
                {
                    MessageBox.Show("Non hai datos para ordenar", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            };
//.........这里部分代码省略.........
开发者ID:jmlb23,项目名称:desenvolvementoInterfaces,代码行数:101,代码来源:Form1.cs

示例5: ValuesPaladin

        public IDictionary<PropertyInfo, float> ValuesPaladin(StatFilter filter)
        {
#if SILVERLIGHT
            Dictionary<PropertyInfo, float> dict = new Dictionary<PropertyInfo, float>();
#else
            SortedList<PropertyInfo, float> dict = new SortedList<PropertyInfo, float>(new PropertyComparer());
#endif
            foreach (PropertyInfo info in PropertyInfoCachePaladin)
            {
                if (info.PropertyType.IsAssignableFrom(typeof(float)))
                {
                    float value = (float)info.GetValue(this, null);
                    if (filter(value))
                    {
                        dict[info] = value;
                    }
                }
            }
#if SILVERLIGHT
            dict.OrderBy(kvp => kvp.Key, new PropertyComparer());
#endif
            return dict;
        }
开发者ID:LucasPeacecraft,项目名称:rawr,代码行数:23,代码来源:StatsPaladin.cs

示例6: LongestUserName

 int LongestUserName(SortedList<decimal, TwitterStatus> collection)
 {
     return collection.OrderBy((status) => status.Value.User.Name.Length)
         .Select((status) => status.Value.User.Name.Length)
         .LastOrDefault();
 }
开发者ID:txdv,项目名称:meetcurses,代码行数:6,代码来源:Timeline.cs


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