LogIn
I don't have account.

SortedDictionary<T> Methods in C#

DevSniper
156 Views

Methods

  1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. 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)
  6. 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)
  7. Equals (Object) :- public virtual bool Equals (object? obj);
    Returns true if specified object is equals to the current object otherwise false.
  8. 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)
  9. GetHashCode() :- public virtual int GetHashCode ();
    Returns a hash code of current object.
  10. GetType() :- public Type GetType ();
    Returns the exact runtime type of current instance.
  11. MemberwiseClone() :- protected object MemberwiseClone ();
    it will creates and return a shallow copy of the current Object.
  12. ToString() :- public virtual string? ToString ();
    It will return a string that represents the current object
  13. 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)