SortedDictionary<T> Methods in C#
DevSniper
156 Views
Methods
- Add :- public void Add (TKey key, TValue value);It will add an element in the SortedDictionary<TKey,TValue> with specified key and value. The time complexity of this method is O(log n)
- Clear :- public void Clear ();it will remove all element from the SortedDictionary<TKey,TValue>. it will set Count property to 0 and release reference of the collection. The time complexity of this method is O(1)
- ContainsKey(TKey) :- public bool ContainsKey (TKey key);Returns true if the specified key is present in the SortedDictionary<TKey,TValue> otherwise false. Time complexity of this method is O(log n)
- ContainsValue(TValue) :- public bool ContainsValue (TValue value);Retruns true if the specified value present in the SortedDictionary<TKey,TValue> otherwise false. This method performs a linear search to find out value. Time complexity of this method is O(n)
- Remove(TKey) :- public bool Remove (TKey key);it will remove specified key element from the SortedDictionary<TKey,TValue>. Return true if element removed successfully otherwise false, also returns false if key not present in the SortedDictionary<TKey,TValue>. The time complexity of this method is o(log n)
- CopyTo(KeyValuePair<TKey,TValue>[], Int32) :- public void CopyTo (System.Collections.Generic.KeyValuePair<TKey,TValue>[] array, int index);It will Copy SortedDictionary<TKey,TValue> elements into provided KeyValuePair<TKey,TValue> array, starting at the specified index. Time complexity of this method is O(n)
- Equals (Object) :- public virtual bool Equals (object? obj);Returns true if specified object is equals to the current object otherwise false.
- GetEnumerator() :- public System.Collections.Generic.SortedDictionary<TKey,TValue>.Enumerator GetEnumerator ();it will return an enumerator of the SortedDictionary<TKey,TValue>. time complexity of this method is O( log n)
- GetHashCode() :- public virtual int GetHashCode ();Returns a hash code of current object.
- GetType() :- public Type GetType ();Returns the exact runtime type of current instance.
- MemberwiseClone() :- protected object MemberwiseClone ();it will creates and return a shallow copy of the current Object.
- ToString() :- public virtual string? ToString ();It will return a string that represents the current object
- TryGetValue(TKey, TValue) :- public bool TryGetValue (TKey key, out TValue value);Returns true if the specified key is present in the SortedDictionary<TKey,TValue> otherwise false, for out param : if key present in the SortedDictionary<TKey,TValue> set value in the TValue param otherwise default value of TValue. Time complexity of this method is O( log n)