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


C# HashTable.ToList方法代码示例

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


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

示例1: Add_1000_Elements_Grow_ShouldWorkCorrectly

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

        // Act
        var expectedElements = new List<KeyValue<string, int>>();
        for (int i = 0; i < 1000; i++)
        {
            hashTable.Add("key" + i, i);
            expectedElements.Add(new KeyValue<string, int>("key" + i, i));
        }

        // Assert
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(expectedElements, actualElements);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:17,代码来源:UnitTestsHashTable.cs

示例2: AddOrReplace_WithDuplicates_ShouldWorkCorrectly

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

        // Act
        hashTable.AddOrReplace("Peter", 555);
        hashTable.AddOrReplace("Maria", 999);
        hashTable.AddOrReplace("Maria", 123);
        hashTable.AddOrReplace("Maria", 6);
        hashTable.AddOrReplace("Peter", 5);

        // Assert
        var expectedElements = new KeyValue<string, int>[]
        {
            new KeyValue<string, int>("Peter", 5),
            new KeyValue<string, int>("Maria", 6)
        };
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(expectedElements, actualElements);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:21,代码来源:UnitTestsHashTable.cs

示例3: Add_EmptyHashTable_NoDuplicates_ShouldAddElement

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

        // Act
        var elements = new KeyValue<string, int>[]
        {
            new KeyValue<string, int>("Peter", 5),
            new KeyValue<string, int>("Maria", 6),
            new KeyValue<string, int>("George", 4),
            new KeyValue<string, int>("Kiril", 5)
        };
        foreach (var element in elements)
        {
            hashTable.Add(element.Key, element.Value);
        }

        // Assert
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(elements, actualElements);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:22,代码来源:UnitTestsHashTable.cs

示例4: Remove_5000_Elements_ShouldWorkCorrectly

    public void Remove_5000_Elements_ShouldWorkCorrectly()
    {
        // Arrange
        var hashTable = new HashTable<string, int>();
        var keys = new List<string>();
        var count = 5000;
        for (int i = 0; i < count; i++)
        {
            var key = Guid.NewGuid().ToString();
            keys.Add(key);
            hashTable.Add(key, i);
        }

        // Assert
        Assert.AreEqual(count, hashTable.Count);

        // Act & Assert
        keys.Reverse();
        foreach (var key in keys)
        {
            hashTable.Remove(key);
            count--;
            Assert.AreEqual(count, hashTable.Count);
        }

        // Assert
        var expectedElements = new List<KeyValue<string, int>>();
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(expectedElements, actualElements);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:30,代码来源:UnitTestsHashTable.cs

示例5: Indexer_AddReplace_WithDuplicates_ShouldWorkCorrectly

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

        // Act
        hashTable["Peter"] = 555;
        hashTable["Maria"] = 999;
        hashTable["Maria"] = 123;
        hashTable["Maria"] = 6;
        hashTable["Peter"] = 5;

        // Assert
        var expectedElements = new KeyValue<string, int>[]
        {
            new KeyValue<string, int>("Peter", 5),
            new KeyValue<string, int>("Maria", 6)
        };
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(expectedElements, actualElements);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:21,代码来源:UnitTestsHashTable.cs

示例6: Clear_ShouldWorkCorrectly

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

        // Assert
        Assert.AreEqual(0, hashTable.Count);

        // Act
        hashTable.Clear();

        // Assert
        Assert.AreEqual(0, hashTable.Count);

        // Arrange
        hashTable.Add("Peter", 5);
        hashTable.Add("George", 7);
        hashTable.Add("Maria", 3);

        // Assert
        Assert.AreEqual(3, hashTable.Count);

        // Act
        hashTable.Clear();

        // Assert
        Assert.AreEqual(0, hashTable.Count);
        var expectedElements = new List<KeyValue<string, int>>();
        var actualElements = hashTable.ToList();
        CollectionAssert.AreEquivalent(expectedElements, actualElements);

        hashTable.Add("Peter", 5);
        hashTable.Add("George", 7);
        hashTable.Add("Maria", 3);

        // Assert
        Assert.AreEqual(3, hashTable.Count);
    }
开发者ID:tockata,项目名称:Data-Structures,代码行数:38,代码来源:UnitTestsHashTable.cs


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