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


C# HashTable.Find方法代码示例

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


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

示例1: Main

        public static void Main()
        {
            var hashtable = new HashTable<int, string>();
            hashtable.Add(5, "five");
            hashtable.Add(3, "tree");
            hashtable.Add(-6, "minus six");
            Console.WriteLine(hashtable.Find(-6));
            Console.WriteLine("All elements");
            foreach (var item in hashtable)
            {
                Console.WriteLine("Key: {0} => Value: {1}", item.Key, item.Value);
            }

            hashtable.Remove(3);
            Console.WriteLine("3 removed from table");
            try
            {
                Console.WriteLine("Searching for 3 in table");
                hashtable.Find(3);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine("Hash table has {0} elements", hashtable.Count);
        }
开发者ID:Moiraines,项目名称:TelerikAcademy,代码行数:27,代码来源:StartUp.cs

示例2: HashTableTest

 public void HashTableTest()
 {
     HashTable<string, int> table = new HashTable<string, int>(100);
     table.Add("brad", 100);
     table.Add("rich", 200);
     table.Remove("rich");
     Assert.AreEqual(100, table.Find("brad"));
     Assert.AreEqual(0, table.Find("rich"));
 }
开发者ID:rich-staackmann,项目名称:CSharp,代码行数:9,代码来源:UnitTest1.cs

示例3: Main

    private static void Main()
    {
        HashTable<string, int> myDictionary = new HashTable<string, int>();

        // Add method test
        myDictionary.Add("kir4o", 5);
        myDictionary.Add("gery", 3);
        myDictionary.Add("lili", 2);

        // Find Method test
        int geryValue;
        Console.WriteLine("Find Method test");
        Console.WriteLine("gery found = {0}, value = {1}",myDictionary.Find("gery", out geryValue), geryValue);
        Console.WriteLine();

        // Remove Method test
        Console.WriteLine("Remove Method test");
        myDictionary.Remove("gery");
        Console.WriteLine("gery found = {0}", myDictionary.Find("gery", out geryValue));
        Console.WriteLine();

        // Count poroperty test
        Console.WriteLine("Count Poroperty test = {0}", myDictionary.Count);
        Console.WriteLine();

        // this[] property tests (intexer tests)
        Console.WriteLine("intexer tests :");
        Console.WriteLine("kir4o value = {0}",myDictionary["kir4o"]);
        myDictionary["kir4o"] = 13;
        Console.WriteLine("kir4o value changed to {0}", myDictionary["kir4o"]);
        Console.WriteLine();

        // Keys property test
        Console.WriteLine("Keys property test :");
        HashSet<string> myKeys = myDictionary.Keys;

        foreach (string key in myKeys)
        {
            Console.WriteLine("Key = {0}",key);
        }
        Console.WriteLine();

        // Foreach test
        Console.WriteLine("Foreach test :");
        foreach (KeyValuePair<string, int> pair in myDictionary)
        {
            Console.WriteLine("{0} -> {1}", pair.Key, pair.Value);
        }
        Console.WriteLine();
    }
开发者ID:KirilToshev,项目名称:Projects,代码行数:50,代码来源:HashTableMain.cs

示例4: Main

    /* Task 4: 
     * Implement the data structure "hash table" in a class HashTable<K,T>. 
     * Keep the data in array of lists of key-value pairs (LinkedList<KeyValuePair<K,T>>[]) 
     * with initial capacity of 16. When the hash table load runs over 75%, perform resizing to 2
     * times larger capacity. Implement the following methods and properties: Add(key, value), Find(key)value,
     * Remove( key), Count, Clear(), this[], Keys. Try to make the hash table to support iterating over its elements 
     * with foreach.
     */

    //Few functionalities are missing. If I have time I will add them as well. 

    static void Main(string[] args)
    {
        var hashTable = new HashTable<string, int>();

        for (int i = 0; i < 100; i++)
        {
            hashTable.Add("Entri" + i, i);
        }

        Console.WriteLine(hashTable.Count());
        Console.WriteLine(hashTable.Find("Entri50"));

        for (int i = 50; i < 100; i++)
        {
            hashTable.Remove("Entri" + i);
        }

        //Will throw an exception
        //Console.WriteLine(hashTable.Find("Entri50"));

        var keys = hashTable.Keys();

        foreach (var key in keys)
        {
            Console.WriteLine(key);
        }

        hashTable.Clear();
        Console.WriteLine(hashTable.Count());
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:41,代码来源:ImplementingHashTable.cs

示例5: Main

        static void Main(string[] args)
        {
            var hash = new HashTable<string, int>();

            for (int i = 0; i < 50; i++)
            {
                var name = "Pesho";
                hash.Add(name + i, i);
                Console.WriteLine("Count: " + hash.Count);
                Console.WriteLine("Length: " + hash.Length);

            }

            var result = hash.Find("Pesho4");
            Console.WriteLine(result);
            Console.WriteLine();

            Console.WriteLine("Count is " + hash.Count);
            hash.Remove("Pesho2");
            Console.WriteLine("Now count is " + hash.Count);

            Console.WriteLine("-------");

            foreach (var item in hash)
            {
                Console.WriteLine(item);
            }
        }
开发者ID:abaditsegay,项目名称:SVN,代码行数:28,代码来源:Program.cs

示例6: FindNewKeyPairShouldWorkCorrectly

        public void FindNewKeyPairShouldWorkCorrectly()
        {
            var hashTable = new HashTable<string, int>();
            hashTable.Add("Ivan", 1);

            Assert.AreEqual(hashTable.Find("Ivan"), 1);
        }
开发者ID:dchakov,项目名称:Data-Structures-and-Algorithms_HW,代码行数:7,代码来源:HashTableTests.cs

示例7: TestIfFindFindsTheValue

        public void TestIfFindFindsTheValue()
        {
            var table = new HashTable<int, int>();

            table.Add(1, 11);
            Assert.AreEqual(11, table.Find(1));
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:7,代码来源:HashTableTests.cs

示例8: Main

        static void Main(string[] args)
        {
            HashTable<string, string> phoneBook = new HashTable<string, string>();

            while (true)
            {
                var line = Console.ReadLine();
                if (line == "search")
                {
                    while (true)
                    {
                        line = Console.ReadLine();
                        if (line == "break")
                        {
                            break;
                        }

                        var entry = phoneBook.Find(line);
                        if (entry != null)
                        {
                            Console.WriteLine("{0} -> {1}", entry.Key, entry.Value);
                        }
                        else
                        {
                            Console.WriteLine("Contact {0} does not exist!", line);
                        }
                    }
                }
                else
                {
                    string[] phoneEntries = line.Split(new string[] { DELIMITER }, StringSplitOptions.RemoveEmptyEntries).ToArray();
                    phoneBook.Add(phoneEntries[0], phoneEntries[1]);
                }
            }
        }
开发者ID:flyer87,项目名称:Data_structures,代码行数:35,代码来源:Program.cs

示例9: Main

        public static void Main()
        {
            var table = new HashTable<int, int>();

            table.Add(1, 11);
            table.Add(2, 12);
            table.Add(3, 13);
            table.Add(4, 14);
            table.Add(5, 15);
            table.Add(6, 16);
            table.Add(7, 17);
            table.Add(8, 18);
            //var four = table.Find(4);
            Console.WriteLine();
            Console.WriteLine(table.Count);
            table.Remove(4);
            table.Remove(4);
            Console.WriteLine();
            Console.WriteLine(table.Count);
            Console.WriteLine();
            var secondfour = table.Find(4);
            Console.WriteLine(table.Count);
            Console.WriteLine(secondfour);
            Console.WriteLine(table[1]);
            table[1] = 15;
            Console.WriteLine(table[1]);
            Console.WriteLine(string.Join(", ", table.Keys));
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:28,代码来源:Startup.cs

示例10: Main

        static void Main()
        {
            HashTable<string, string> hashTable = new HashTable<string, string>();
            hashTable.Add("1", "aa1");
            hashTable.Add("2", "22a");
            hashTable.Add("3", "wwer");
            hashTable.Add("4", "rrrr");
            hashTable.Add("5", "qqqq");
            hashTable.Add("6", "tttt");

            Console.WriteLine(hashTable.Find("2"));
            Console.WriteLine("Count: {0}", hashTable.Count);

            hashTable.Remove("1");
            Console.WriteLine("Count: {0}", hashTable.Count);
            Console.WriteLine(hashTable["3"]);

            Console.WriteLine("\nKeys: ");
            foreach (var item in hashTable.Keys)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine("\nIteration with foreach:");
            foreach (var item in hashTable)
            {
                Console.WriteLine("{0}: {1}", item.Key, item.Value);
            }

        }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:30,代码来源:Program.cs

示例11: Main

        static void Main(string[] args)
        {
            var table = new HashTable<int, string>();
            table.Add(5,"Pencho");
            table.Add(1,"Mariika");
            table.Add(199,"Kircho");

            Console.WriteLine(table.Find(1));
            Console.WriteLine(string.Join(",",table.Keys));
            foreach (var val in table)
            {
                Console.WriteLine(val.Value);
            }
            table.Remove(199);
            foreach (var val in table)
            {
                Console.WriteLine(val.Value);
            }

            Console.WriteLine(table.Count);
            Console.WriteLine(table.Capacity);

            table.Add(10, "Pencho");
            table.Add(11, "Mariika");
            table.Add(12, "Kircho");
            table.Add(13, "Pencho");
            table.Add(14, "Mariika");
            table.Add(15, "Kircho");
            table.Add(16, "Pencho");
            table.Add(17, "Mariika");
            table.Add(18, "Kircho");
            table.Add(19, "Pencho");
            table.Add(20, "Mariika");
            table.Add(21, "Kircho");
            table.Add(22, "Pencho");
            table.Add(23, "Mariika");
            table.Add(24, "Kircho");
            table.Add(25, "Pencho");
            table.Add(26, "Mariika");
            table.Add(27, "Kircho");
            table.Add(28, "Pencho");
            table.Add(29, "Mariika");
            table.Add(30, "Kircho");

            Console.WriteLine(table.Find(19));
            Console.WriteLine(table.Capacity);
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:47,代码来源:Program.cs

示例12: Main

        internal static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Presenting the functionality of the data structure 'Hash table'***");
            Console.Write(decorationLine);

            HashTable<string, int> clubsPoints = new HashTable<string, int>();

            Console.WriteLine("---Add operation---");
            clubsPoints.Add("Rabbits-O!", 15);
            clubsPoints.Add("Frogssy", 19);
            clubsPoints.Add("Puma Runners", 17);
            clubsPoints.Add("Lion Kings", 33);
            Console.WriteLine("Count = " + clubsPoints.Count);
            Console.WriteLine();

            Console.WriteLine("---Iterator functionality---");
            PrintClubsPoints(clubsPoints);
            Console.WriteLine();

            Console.WriteLine("---Remove operation---");
            bool isRemoved = clubsPoints.Remove("Frogssy");
            Console.WriteLine("Are 'Frogssy' removed: " + isRemoved);
            Console.WriteLine("Count = " + clubsPoints.Count);
            Console.WriteLine("Hash table after removal:");
            PrintClubsPoints(clubsPoints);
            Console.WriteLine();

            Console.WriteLine("---Indexer---");
            Console.WriteLine("'Lion Kings' points so far: " + clubsPoints["Lion Kings"]);
            clubsPoints["Rabbits-O!"] += 3;
            Console.WriteLine("'Rabbits-O!' points after a win: " + clubsPoints["Rabbits-O!"]);
            Console.WriteLine();

            Console.WriteLine("---Find operation---");
            Console.WriteLine("Info about 'Puma Runners'" + clubsPoints.Find("Puma Runners"));
            Console.WriteLine();

            Console.WriteLine("---ContainsKey operation---");
            Console.WriteLine("Is there a club 'Birdy'? - " + clubsPoints.ContainsKey("Birdy"));
            Console.WriteLine("Is there a club 'Rabbits-O!'? - " + clubsPoints.ContainsKey("Rabbits-O!"));
            Console.WriteLine();

            Console.WriteLine("---Keys property---");
            Console.Write("All clubs names are: ");
            Console.WriteLine(string.Join(", ", clubsPoints.Keys));
            Console.WriteLine();

            Console.WriteLine("---Values property---");
            Console.Write("All club's points are: ");
            Console.WriteLine(string.Join(", ", clubsPoints.Values));
            Console.WriteLine();

            Console.WriteLine("---Clear operation---");
            clubsPoints.Clear();
            Console.WriteLine("Elements count after clearing: " + clubsPoints.Count);
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:58,代码来源:HashTableDemo.cs

示例13: FindNewKeyPairShouldThrowWhenKeyNotExists

        public void FindNewKeyPairShouldThrowWhenKeyNotExists()
        {
            var hashTable = new HashTable<string, int>
            {
                {"Ivan", 1}
            };

            hashTable.Find("Asen");
        }
开发者ID:Nikolay-D,项目名称:DataStructuresAndAlgorithms,代码行数:9,代码来源:HashTableTests.cs

示例14: 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

示例15: FindNonExistingEntryTest

        public void FindNonExistingEntryTest()
        {
            HashTable<string, int> studentMarks = new HashTable<string, int>();
            studentMarks.Add("Ivan", 5);
            studentMarks.Add("Pesho", 4);
            studentMarks.Add("Lili", 6);
            studentMarks.Add("Gosho", 3);

            studentMarks.Find("Marin");
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:10,代码来源:FindOperationTests.cs


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