C# Collection

IMPORTANT PROPERTIES AND METHODS OF SORTEDLIST in C#

PropertiesDescription
CapacityGets or sets the number of elements that the SortedList<TKey,TValue> can store.
CountGets the total number of elements exists in the SortedList<TKey,TValue>.
IsReadOnlyReturns a boolean indicating whether the SortedList<TKey,TValue> is read-only.
ItemGets or sets the element with the specified key in the SortedList<TKey,TValue>.
KeysGet list of keys of SortedList<TKey,TValue>.
ValuesGet list of values in SortedList<TKey,Tvalue>.

IMPORTANT METHODS

MethodsDescription
void Add(TKey key, TValue value)Add key-value pairs into SortedList<TKey, TValue>.
void Remove(TKey key)Removes element with the specified key.
void RemoveAt(int index)Removes element at the specified index.
bool ContainsKey(TKey key)Checks whether the specified key exists in SortedList<TKey, TValue>.
bool ContainsValue(TValue value)Checks whether the specified key exists in SortedList<TKey, TValue>.
void Clear()Removes all the elements from SortedList<TKey, TValue>.
int IndexOfKey(TKey key)Returns an index of specified key stored in internal array of SortedList<TKey, TValue>.
int IndexOfValue(TValue value)Returns an index of specified value stored in internal array of SortedList<TKey, TValue>
bool TryGetValue(TKey key, out TValue value)Returns true and assigns the value with specified key, if key does not exists then return false.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.