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


C# HashTable.Remove方法代码示例

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


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

示例1: Main

    public static void Main()
    {
        var grades = new HashTable<string, int>();
        Console.WriteLine("Grades:" + string.Join(",", grades));
        Console.WriteLine("--------------------");

        grades.Add("Peter", 3);
        grades.Add("Maria", 6);
        grades["George"] = 5;
        Console.WriteLine("Grades:" + string.Join(",", grades));
        Console.WriteLine("--------------------");

        grades.AddOrReplace("Peter", 33);
        grades.AddOrReplace("Tanya", 4);
        grades["George"] = 55;
        Console.WriteLine("Grades:" + string.Join(",", grades));
        Console.WriteLine("--------------------");

        Console.WriteLine("Keys: " + string.Join(", ", grades.Keys));
        Console.WriteLine("Values: " + string.Join(", ", grades.Values));
        Console.WriteLine("Count = " + string.Join(", ", grades.Count));
        Console.WriteLine("--------------------");

        grades.Remove("Peter");
        grades.Remove("George");
        grades.Remove("George");
        Console.WriteLine("Grades:" + string.Join(",", grades));
        Console.WriteLine("--------------------");

        Console.WriteLine("ContainsKey[\"Tanya\"] = " + grades.ContainsKey("Tanya"));
        Console.WriteLine("ContainsKey[\"George\"] = " + grades.ContainsKey("George"));
        Console.WriteLine("Grades[\"Tanya\"] = " + grades["Tanya"]);
        Console.WriteLine("--------------------");
    }
开发者ID:peterkirilov,项目名称:SoftUni-1,代码行数:34,代码来源:HashTableExample.cs

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

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

示例4: TestRemoveMethod

        public void TestRemoveMethod()
        {
            var hashTable = new HashTable<int, int>();

            hashTable.Add(1, 2);
            hashTable[2] = 3;

            Assert.IsTrue(hashTable.Remove(2));
            Assert.IsFalse(hashTable.Remove(-1));
        }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:10,代码来源:HashTableTests.cs

示例5: Main

    /* 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.
     * */
    static void Main(string[] args)
    {
        var ht = new HashTable<string, int>();

        foreach (var word in new[] { "aaa", "aaa", "bbb", "ccc", "aaa", "bbb" })
            ht.Add(word, 1 + ht.GetOrDefault(word, 0));

        Debug.Assert(ht["aaa"] == 3);
        Debug.Assert(ht["bbb"] == 2);
        Debug.Assert(ht["ccc"] == 1);

        var ht2 = new HashTable<MockHash, string>(4);

        Debug.Assert(ht2.Count == 0);
        Debug.Assert(ht2.OccupiedBuckets == 0);
        Debug.Assert(ht2.Capacity == 4);

        ht2[new MockHash(0, 0)] = "00";

        Debug.Assert(ht2.Count == 1);
        Debug.Assert(ht2.OccupiedBuckets == 1);
        Debug.Assert(ht2.Capacity == 4);

        ht2[new MockHash(0, 1)] = "01";

        Debug.Assert(ht2.Count == 2);
        Debug.Assert(ht2.OccupiedBuckets == 1);
        Debug.Assert(ht2.Capacity == 4);

        ht2[new MockHash(1, 2)] = "12";

        Debug.Assert(ht2.Count == 3);
        Debug.Assert(ht2.OccupiedBuckets == 2);
        Debug.Assert(ht2.Capacity == 8);

        ht2[new MockHash(1, 3)] = "13";

        Debug.Assert(ht2.Count == 4);
        Debug.Assert(ht2.OccupiedBuckets == 2);
        Debug.Assert(ht2.Capacity == 8);

        Debug.Assert(ht2.Remove(new MockHash(1, 3)));
        Debug.Assert(!ht2.Remove(new MockHash(1, 3)));

        Debug.Assert(ht2.Count == 3);
        Debug.Assert(ht2.OccupiedBuckets == 2);
        Debug.Assert(ht2.Capacity == 8);

        Debug.Assert(ht2.Remove(new MockHash(1, 2)));
        Debug.Assert(!ht2.Remove(new MockHash(1, 2)));

        Debug.Assert(ht2.Count == 2);
        Debug.Assert(ht2.OccupiedBuckets == 1);
        Debug.Assert(ht2.Capacity == 8);
    }
开发者ID:staafl,项目名称:ta-hw-dsa,代码行数:61,代码来源:program.cs

示例6: Remove_GivenTheSameKeySecondTime_ThrownExpectedException

 public void Remove_GivenTheSameKeySecondTime_ThrownExpectedException()
 {
     var hashTable = new HashTable<int, int>();
     hashTable.Add(31, 2);
     hashTable.Add(21, 30);
     hashTable.Add(11, 7);
     hashTable.Add(41, 25);
     hashTable.Add(7, 58);
     hashTable.Remove(11);
     hashTable.Remove(11);
 }
开发者ID:TatyanaBelovets,项目名称:ASP.NET_MVC_Training_Classwork,代码行数:11,代码来源:Tests.cs

示例7: Main

        static void Main(string[] args)
        {
            
            HashSet<int> p = new HashSet<int>();
            HashTable<int, int> hashTable = new HashTable<int, int>(2);
            hashTable.Add(3, 4);
            hashTable.Add(7, 4);
            Console.WriteLine(hashTable.Count);
            hashTable.Remove(3);
            Console.WriteLine(hashTable.Count);
            hashTable.Add(3, 4);
            hashTable.Add(8, 4);
            hashTable.Add(13, 4);
            hashTable.Add(3333, 4);
            hashTable.Add(124, 4);
            hashTable.Add(412412, 4);
            hashTable[8] = 25;
            hashTable[8] = -45;
            Console.WriteLine(hashTable.Count);
            foreach (var item in hashTable)
            {
                Console.WriteLine("Key {0}, Value {1}", item.Key, item.Value);
            }
            // Console.WriteLine(hashTable.Count);

            // Console.WriteLine(hashTable.Find(3));

            IEnumerable<int> keys = hashTable.Keys;

            foreach (var key in keys)
            {
                Console.Write(key + ",");
            }
            Console.WriteLine();
            hashTable.Add(17, 34);
            hashTable.Remove(8);
            hashTable.Remove(3333);
            hashTable.Add(-4, 23);
            keys = hashTable.Keys;

            foreach (var key in keys)
            {
                Console.Write(key + ",");
            }
            Console.WriteLine();
            hashTable.Clear();
            Console.WriteLine(hashTable.Count);
            foreach (var item in hashTable)
            {
                Console.WriteLine("Key {0}, Value {1}", item.Key, item.Value);
            }
        }
开发者ID:RRRRRRRRRR,项目名称:thegodmode.github.com,代码行数:52,代码来源:Test.cs

示例8: RemoveShouldReturnTrueIfTheKeyIsFoundAndRemovedFromTheHashTable

 public void RemoveShouldReturnTrueIfTheKeyIsFoundAndRemovedFromTheHashTable()
 {
     var testHashTable = new HashTable<int, int>();
     testHashTable.Set(1, 1);
     var removed = testHashTable.Remove(1);
     Assert.AreEqual(true, removed);
 }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs

示例9: RemoveNullKeyElementTest

        public void RemoveNullKeyElementTest()
        {
            HashTable<Point, int> pointsCounts = new HashTable<Point, int>();
            pointsCounts.Add(new Point(3, 2), 11);

            pointsCounts.Remove(null);
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:7,代码来源:RemoveOperationTests.cs

示例10: RemoveShouldReturnFalseIfTheKeyIsNotFound

 public void RemoveShouldReturnFalseIfTheKeyIsNotFound()
 {
     var testHashTable = new HashTable<int, int>();
     testHashTable.Set(1, 1);
     var removed = testHashTable.Remove(2);
     Assert.AreEqual(false, removed);
 }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:7,代码来源:HashTableTests.cs

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

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

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

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

示例15: Main

    static void Main()
    {
        HashTable<string, int> hash = new HashTable<string, int>(32);

        hash.Add("Pesho", 6);
        hash.Add("Pesho", 6);
        hash.Add("Pesho", 3);
        hash.Add("Gosho", 9);
        hash.Add("Tosho", 4);
        hash.Add("Viko", 7);
        hash.Add("Viko", 7);
        hash.Add("high 5", 7);
        hash["Johnatan"] = 3333;
        hash["viko"] = 1111111;
        hash.Remove("Tosho");

        foreach (var item in hash)
        {
            Console.WriteLine("{0} -> {1}", item.Key, item.Value);
        }

        hash.Clear();

        foreach (var item in hash)
        {
            Console.WriteLine("{0} -> {1}", item.Key, item.Value);
        }
    }
开发者ID:bahtev,项目名称:TelerikAcademy,代码行数:28,代码来源:Program.cs


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