System.Collections.Specialized.OrderedDictionary.Remove C# (CSharp) Method

Remove() public method

public Remove ( object key ) : void
key object
return void
        public void Remove(object key)
        {
            if (_readOnly)
            {
                throw new NotSupportedException(SR.OrderedDictionary_ReadOnly);
            }
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            int index = IndexOfKey(key);
            if (index < 0)
            {
                return;
            }

            objectsTable.Remove(key);
            objectsArray.RemoveAt(index);
        }

Usage Example

示例#1
0
        public void CountTests()
        {
            var d = new OrderedDictionary();
            Assert.Equal(0, d.Count);

            for (int i = 0; i < 1000; i++)
            {
                d.Add(i, i);
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.Remove(i);
                Assert.Equal(1000 - i - 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d[(object)i] = i;
                Assert.Equal(i + 1, d.Count);
            }

            for (int i = 0; i < 1000; i++)
            {
                d.RemoveAt(0);
                Assert.Equal(1000 - i - 1, d.Count);
            }
        }
All Usage Examples Of System.Collections.Specialized.OrderedDictionary::Remove