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


C# HashTable.OrderBy方法代码示例

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


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

示例1: Main

    public static void Main()
    {
        var topCities = new HashTable<string, double>();

        // Add(key, value)
        topCities.Add("Tokyo", 36.9);
        topCities.Add("Jakarta", 12.8);
        topCities.Add("Seoul", 25.7);
        topCities.Add("Beijing", 23.7);
        topCities.Add("Shanghai", 21.7);

        // foreach
        foreach (var pair in topCities.OrderBy(p => -p.Value))
        {
            Console.WriteLine("{0, -8} -> {1}", pair.Key, pair.Value);
        }

        // Add already existing key
        try
        {
            topCities.Add("Jakarta", 0);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        
        // Keys
        Console.WriteLine("Keys: {0}", string.Join(", ", topCities.Keys));

        // Count
        Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);

        // Find(key)
        topCities.PrintValue("Tokyo");
        Console.WriteLine("Jakarta -> {0}", topCities.Find("Jakarta"));

        // this[key]
        Console.WriteLine("Beijing -> {0}", topCities["Beijing"]);

        // ContainsKey(key)
        Console.WriteLine("Hash table contains 'Delhi': {0}", topCities.ContainsKey("Delhi"));

        // Remove(key)
        topCities.Remove("Seoul");
        Console.WriteLine("Remove 'Seoul'");
        Console.WriteLine("Keys: {0}", string.Join(", ", topCities.Keys));
        Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);

        // Remove non-existing
        Console.WriteLine("Removing 'Sofia' -> {0}", topCities.Remove("Sofia"));

        // Clear
        topCities.Clear();
        Console.WriteLine("Clear hash table");
        Console.WriteLine("Number of key-value pairs: {0}", topCities.Count);
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:57,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            HashTable<char, int> table = new HashTable<char, int>();
            foreach (char c in input)
            {
                if (!table.ContainsKey(c))
                {
                    table[c] = 0;
                }
                table[c]++;
            }

            foreach (var item in table.OrderBy(s => s.Key))
            {
                Console.WriteLine(item);
            }
        }
开发者ID:EBojilova,项目名称:SoftUni-3,代码行数:18,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var symbols = new HashTable<char, int>();
            foreach (var ch in input)
            {
                if (!symbols.ContainsKey(ch))
                {
                    symbols[ch] = 0;
                }

                symbols[ch]++;
            }

            var sortedSymbols = symbols.OrderBy(s => s.Key);
            foreach (var symbol in sortedSymbols)
            {
                Console.WriteLine("{0} -> {1} time/s", symbol.Key, symbol.Value);
            }
        }
开发者ID:peterkirilov,项目名称:SoftUni-1,代码行数:20,代码来源:CountSymbols.cs

示例4: Main

        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            HashTable<char, int> dictionary = new HashTable<char, int>();
            foreach (char ch in input)
            {
                if(!dictionary.ContainsKey(ch))
                {
                    dictionary.Add(ch, 0);
                }

                dictionary[ch]++;
            }

            var result = dictionary.OrderBy(x => x.Key);
            foreach (var ch in result)
            {
                Console.WriteLine("{0}: {1} time/s", ch.Key, ch.Value);
            }
        }
开发者ID:AsenTahchiyski,项目名称:SoftUni,代码行数:20,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            var symbols_occur = new HashTable<char, int>();
            string text = Console.ReadLine();

            for (int i = 0; i < text.Length; i++)
            {
                if (!symbols_occur.ContainsKey(text[i]))
                {
                    symbols_occur[text[i]] = 0;
                }

                symbols_occur[text[i]] += 1;
            }

            var ordered_symbols_occur = symbols_occur.OrderBy(element => element.Key);

            foreach (var symbol in ordered_symbols_occur)
            {
                Console.WriteLine("{0}: {1} time/s", symbol.Key, symbol.Value);
            }
        }
开发者ID:flyer87,项目名称:Data_structures,代码行数:22,代码来源:Program.cs

示例6: Main

        public static void Main()
        {
            var dictionary = new HashTable<char, int>();
            var input = Console.ReadLine();

            foreach (var character in input)
            {
                if (!dictionary.ContainsKey(character))
                {
                    dictionary.Add(character, 1);
                }
                else
                {
                    dictionary[character]++;
                }
            }

            foreach (var element in dictionary
                .OrderBy(element => element.Key))
            {
                Console.WriteLine("{0}: {1} time/s", element.Key, element.Value);
            }
        }
开发者ID:Zakkgard,项目名称:Data-Structures-and-Algorithms,代码行数:23,代码来源:CountSymbols.cs

示例7: Main

        static void Main()
        {
            string input = Console.ReadLine();
            var countOfCharacterOccurrences = new HashTable<char, int>();

            for (int i = 0; i < input.Length; i++)
            {
                char currentChar = input[i];
                if (!countOfCharacterOccurrences.ContainsKey(currentChar))
                {
                    countOfCharacterOccurrences[currentChar] = 0;
                }

                countOfCharacterOccurrences[currentChar]++;
            }

            var CharacterOccurrencesSortedByKey = countOfCharacterOccurrences.OrderBy(e => e.Key);

            foreach (var element in CharacterOccurrencesSortedByKey)
            {
                Console.WriteLine("{0}: {1} time/s", element.Key, element.Value);
            }
        }
开发者ID:bobosam,项目名称:DataStructures,代码行数:23,代码来源:CountSymbols.cs

示例8: Main

        static void Main()
        {
            string text = Console.ReadLine();

            HashTable<char, int> hashTable = new HashTable<char, int>();

            foreach (char ch in text)
            {
                if (!hashTable.ContainsKey(ch))
                {
                    hashTable[ch] = 0;
                }

                hashTable[ch]++;
            }

            KeyValue<char, int>[] arr = hashTable.OrderBy(kv => kv.Key).ToArray();

            foreach (var keyValue in arr)
            {
                Console.WriteLine("{0} : {1} time/s", keyValue.Key, keyValue.Value);
            }
        }
开发者ID:dev-velkov,项目名称:Software-University-Courses,代码行数:23,代码来源:CountSymbols.cs


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