System.Collections.SortedList.Clear C# (CSharp) Метод

Clear() публичный Метод

public Clear ( ) : void
Результат void
        public virtual void Clear()
        {
            // clear does not change the capacity
            _version++;
            Array.Clear(_keys, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
            Array.Clear(_values, 0, _size); // Don't need to doc this but we clear the elements so that the gc can reclaim the references.
            _size = 0;
        }

Usage Example

Пример #1
0
        public void TestClearBasic()
        {
            StringBuilder sblMsg = new StringBuilder(99);

            SortedList sl2 = null;

            StringBuilder sbl3 = new StringBuilder(99);
            StringBuilder sbl4 = new StringBuilder(99);
            StringBuilder sblWork1 = new StringBuilder(99);

            String s1 = null;
            String s2 = null;

            int i = 0;
            //
            // 	Constructor: Create SortedList using this as IComparer and default settings.
            //
            sl2 = new SortedList(this);

            //  Verify that the SortedList is not null.
            Assert.NotNull(sl2);

            //  Verify that the SortedList is empty.
            Assert.Equal(0, sl2.Count);

            //  now Clear the list and verify the Count
            sl2.Clear();    //removes 0 element
            Assert.Equal(0, sl2.Count);

            //  Testcase: add few key-val pairs
            for (i = 0; i < 100; i++)
            {
                sblMsg.Length = 0;
                sblMsg.Append("key_");
                sblMsg.Append(i);
                s1 = sblMsg.ToString();

                sblMsg.Length = 0;
                sblMsg.Append("val_");
                sblMsg.Append(i);
                s2 = sblMsg.ToString();

                sl2.Add(s1, s2);
            }

            //  now get the list Count and verify
            Assert.Equal(100, sl2.Count);

            //  now Clear the list and verify the Count
            sl2.Clear(); //removes all the 100 elements
            Assert.Equal(0, sl2.Count);
        }
All Usage Examples Of System.Collections.SortedList::Clear