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


C# HashTable.Add方法代码示例

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


在下文中一共展示了HashTable.Add方法的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: InsertValueByDuplicatedKey_ExpectedException

        public void InsertValueByDuplicatedKey_ExpectedException()
        {
            HashTable<int, int> hashTable = new HashTable<int, int>(10);

            hashTable.Add(1, 1);
            hashTable.Add(1, 2);
        }
开发者ID:VictoriaVlasenco,项目名称:ASP.NET.Vlasenco.Test,代码行数:7,代码来源:TestHashTable.cs

示例3: AddDuplicateKeyElementsTest

        public void AddDuplicateKeyElementsTest()
        {
            HashTable<int, char> alphabet = new HashTable<int, char>();

            alphabet.Add(1, 'A');
            alphabet.Add(1, 'a');
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:7,代码来源:AddOperationTests.cs

示例4: Main

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

            for (int i = 0; i < 17; i++)
            {
                table.Add(i, (i + 1).ToString());
            }

            Console.WriteLine(table[15]);

            table.Clear();

            for (int i = 0; i < 3000; i++)
            {
                table.Add(i, (i + 1).ToString());
            }

            Console.WriteLine(table[1457]);

            //table.Add(1, "test");
            //table.Add(2, "test");
            ////table.Remove(1);
            //Console.WriteLine(table[1]);
        }
开发者ID:Jarolim,项目名称:AllMyHomeworkForTelerikAcademy,代码行数:25,代码来源:Sample.cs

示例5: AddShouldThrowExceptionWhenTheSameKeyIsAlreadyPresent

        public void AddShouldThrowExceptionWhenTheSameKeyIsAlreadyPresent()
        {
            var hashtable = new HashTable<string, int>();

            hashtable.Add("gosho", 12);
            hashtable.Add("gosho", 2);
        }
开发者ID:Novkirishki,项目名称:Data-Structures-and-Algorithms,代码行数:7,代码来源:HashTableTests.cs

示例6: Main

    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:bobosam,项目名称:DataStructures,代码行数:34,代码来源:HashTableExample.cs

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

示例8: SetNonExistingElementTest

        public void SetNonExistingElementTest()
        {
            HashTable<int, char> alphabet = new HashTable<int, char>();
            alphabet.Add(1, 'A');
            alphabet.Add(2, 'B');
            alphabet.Add(3, 'C');

            alphabet[4] = 'D';
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:9,代码来源:IndexerTests.cs

示例9: GetNonExistingElementTest

        public void GetNonExistingElementTest()
        {
            HashTable<int, char> alphabet = new HashTable<int, char>();
            alphabet.Add(1, 'A');
            alphabet.Add(2, 'B');
            alphabet.Add(3, 'C');

            char dLetter = alphabet[4];
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:9,代码来源:IndexerTests.cs

示例10: AddingNewKeyPairShouldCountCorrectly

        public void AddingNewKeyPairShouldCountCorrectly()
        {
            var hashTable = new HashTable<string, int>();
            hashTable.Add("Ivan", 1);
            hashTable.Add("Ivan1", 2);
            hashTable.Add("Ivan2", 3);

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

示例11: TestIfAddingASameKeyThrows

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

            table.Add(1, 11);
            table.Add(1, 12);
            var count = table.Count;
            Assert.AreEqual(8, count);
        }
开发者ID:radenkovn,项目名称:Telerik-Homework,代码行数:9,代码来源:HashTableTests.cs

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

示例13: Add_EmptyHashTable_Duplicates_ShouldThrowException

    public void Add_EmptyHashTable_Duplicates_ShouldThrowException()
    {
        // Arrange
        var hashTable = new HashTable<string, string>();

        // Act
        hashTable.Add("Peter", "first");
        hashTable.Add("Peter", "second");
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:9,代码来源:UnitTestsHashTable.cs

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

示例15: Add_GivenKeyAndValue_PairInATable

 public void Add_GivenKeyAndValue_PairInATable()
 {
     var hashTable = new HashTable<int, int>();
     hashTable.Add(5, 2);
     hashTable.Add(48, 30);
     hashTable.Add(11, 7);
     hashTable.Add(78, 25);
     hashTable.Add(7, 58);
     Assert.AreEqual(7, hashTable.SearchByKey(58));
 }
开发者ID:TatyanaBelovets,项目名称:ASP.NET_MVC_Training_Classwork,代码行数:10,代码来源:Tests.cs


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