SortedDictionary<TKey, TValue> Constructor (IComparer<TKey>^)
Initializes a new instance of the SortedDictionary<TKey, TValue> class that is empty and uses the specified IComparer<T> implementation to compare keys.
Assembly: System (in System.dll)
Parameters
- comparer
-
Type:
System.Collections.Generic::IComparer<TKey>^
The IComparer<T> implementation to use when comparing keys, or null to use the default Comparer<T> for the type of the key.
Every key in a SortedDictionary<TKey, TValue> must be unique according to the specified comparer.
SortedDictionary<TKey, TValue> requires a comparer implementation to perform key comparisons. If comparer is null, this constructor uses the default generic equality comparer, Comparer<T>::Default. If type TKey implements the System::IComparable<T> generic interface, the default comparer uses that implementation.
This constructor is an O(1) operation.
The following code example creates a SortedDictionary<TKey, TValue> with a case-insensitive comparer for the current culture. The example adds four elements, some with lower-case keys and some with upper-case keys. The example then attempts to add an element with a key that differs from an existing key only by case, catches the resulting exception, and displays an error message. Finally, the example displays the elements in case-insensitive sort order.
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone Silverlight
Available since 8.0
Windows Phone
Available since 8.1