SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.Clear method is used to remove all the elements from a SortedList object.
- A SortedList element can be accessed by its key or by its index.
- A SortedList object internally maintains two arrays to store the elements of the list, i.e, one array for the keys and another array for the associated values.
- A key cannot be null, but a value can be.
- The capacity of a SortedList object is the number of elements the SortedList can hold.
- A SortedList does not allow duplicate keys.
- Operations on a SortedList object tend to be slower than operations on a Hashtable object because of the sorting.
- Elements in this collection can be accessed using an integer index. Indexes in this collection are zero-based.
public virtual void Clear ();
- NotSupportedException : If the SortedList object is read-only or has a fixed size.
Number of elements in SortedList is : 7 capacity of SortedList is : 16 Number of elements in SortedList is : 0 capacity of SortedList is : 16
- This method is an O(n) operation, where n is Count.
- Count is set to zero and references to other objects from elements of the collection are also released.
- Capacity remains unchanged. To reset the capacity of the SortedList object, call TrimToSize or set the Capacity property directly.
- Trimming an empty SortedList sets the capacity of the SortedList to the default capacity.
- C# | Remove the element with the specified key from a SortedList
- C# | Remove from the specified index of a SortedList
- C# | Get the number of elements contained in SortedList
- C# | Copying the SortedList elements to an Array Object
- C# | Setting the capacity to the actual number of elements in a SortedList object
- C# | Check if two SortedList objects are equal
- C# | Creating a synchronized (thread-safe) wrapper for a SortedList object
- Difference between SortedList and SortedDictionary in C#
- C# | Check if a SortedList is read-only
- C# | How to add key/value pairs in SortedList
- C# | How to create a SortedList
- C# | Check if a SortedList object contains a specific value
- C# | Search in a SortedList object
- C# | Check if a SortedList object is synchronized
- C# | Check if a SortedList object has a fixed size
- C# | SortedList Class
- C# | Capacity of a SortedList
- C# | Get or set the value associated with specified key in SortedList
- C# | Getting the keys in a SortedList object
- C# | Getting the Values in a SortedList object
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.