See the Remarks section for details.
KGySoft.CollectionsStringKeyedDictionaryTValue
Namespace: KGySoft.Collections
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.0.0-preview.3
[SerializableAttribute] public class StringKeyedDictionary<TValue> : IStringKeyedDictionary<TValue>, IDictionary<string, TValue>, ICollection<KeyValuePair<string, TValue>>, IEnumerable<KeyValuePair<string, TValue>>, IEnumerable, IDictionary, ICollection, IStringKeyedReadOnlyDictionary<TValue>, IReadOnlyDictionary<string, TValue>, IReadOnlyCollection<KeyValuePair<string, TValue>>, ISerializable, IDeserializationCallback
Type Parameters
- TValue
- The type of the value.
The StringKeyedDictionaryTValue type exposes the following members.
Name | Description | |
---|---|---|
![]() | StringKeyedDictionaryTValue |
Initializes a new instance of the StringKeyedDictionaryTValue class
using ordinal comparison.
|
![]() | StringKeyedDictionaryTValue(StringSegmentComparer) |
Initializes a new instance of the StringKeyedDictionaryTValue class
using the specified comparer.
|
![]() | StringKeyedDictionaryTValue(Boolean, Boolean) |
Initializes a new instance of the StringKeyedDictionaryTValue class
that uses an ordinal comparer that satisfies the specified parameters.
|
![]() | StringKeyedDictionaryTValue(IDictionaryString, TValue, StringSegmentComparer) |
Initializes a new instance of the StringKeyedDictionaryTValue class from the specified dictionary
using the specified comparer.
|
![]() | StringKeyedDictionaryTValue(IEnumerableKeyValuePairString, TValue, StringSegmentComparer) |
Initializes a new instance of the StringKeyedDictionaryTValue class from the specified collection
using the specified comparer.
|
![]() | StringKeyedDictionaryTValue(Int32, StringSegmentComparer) |
Initializes a new instance of the StringKeyedDictionaryTValue class
using the specified capacity and comparer.
|
![]() | StringKeyedDictionaryTValue(SerializationInfo, StreamingContext) |
Initializes a new instance of the StringKeyedDictionaryTValue class from serialized data.
|
![]() | StringKeyedDictionaryTValue(Int32, Boolean, Boolean) |
Initializes a new instance of the StringKeyedDictionaryTValue class
using the specified capacity and an ordinal comparer that satisfies the specified parameters.
|
Name | Description | |
---|---|---|
![]() | Count |
Gets number of elements currently stored in this StringKeyedDictionaryTValue instance.
|
![]() | ItemReadOnlySpanChar |
Gets the value associated with the specified key.
|
![]() | ItemString |
Gets or sets the value associated with the specified key.
|
![]() | ItemStringSegment |
Gets the value associated with the specified key.
|
![]() | Keys |
Gets the keys stored in the dictionary.
|
![]() | Values |
Gets the values stored in the dictionary.
|
Name | Description | |
---|---|---|
![]() | Add |
Adds an element with the provided key and value to the StringKeyedDictionaryTValue.
|
![]() | Clear |
Removes all keys and values from the StringKeyedDictionaryTValue.
|
![]() | ContainsKey(ReadOnlySpanChar) |
Determines whether this instance contains an element with the specified key.
|
![]() | ContainsKey(String) |
Determines whether the StringKeyedDictionaryTValue contains a specific key.
|
![]() | ContainsKey(StringSegment) |
Determines whether this instance contains an element with the specified key.
|
![]() | ContainsValue |
Determines whether the StringKeyedDictionaryTValue contains a specific value.
|
![]() | GetEnumerator |
Returns an enumerator that iterates through the StringKeyedDictionaryTValue.
|
![]() | GetObjectData |
In a derived class populates a SerializationInfo with the additional data of the derived type needed to serialize the target object.
|
![]() | GetValueOrDefault(ReadOnlySpanChar) |
Tries to get the value from the dictionary for the given key.
|
![]() | GetValueOrDefault(String) |
Tries to get the value from the dictionary for the given key.
|
![]() | GetValueOrDefault(StringSegment) |
Tries to get the value from the dictionary for the given key.
|
![]() | GetValueOrDefaultTActualValue(ReadOnlySpanChar, TActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValue parameter can have a more specific type than TValue.
|
![]() | GetValueOrDefaultTActualValue(ReadOnlySpanChar, FuncTActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValueFactory can return an instance of a more specific type than TValue.
|
![]() | GetValueOrDefaultTActualValue(String, TActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValue parameter can have a more specific type than TValue.
|
![]() | GetValueOrDefaultTActualValue(String, FuncTActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValueFactory can return an instance of a more specific type than TValue.
|
![]() | GetValueOrDefaultTActualValue(StringSegment, TActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValue parameter can have a more specific type than TValue.
|
![]() | GetValueOrDefaultTActualValue(StringSegment, FuncTActualValue) |
Tries to get the typed value from the dictionary for the given key.
The defaultValueFactory can return an instance of a more specific type than TValue.
|
![]() | OnDeserialization |
In a derived class restores the state the deserialized instance.
|
![]() | Remove |
Removes the value with the specified key from the StringKeyedDictionaryTValue.
|
![]() | TryGetValue(ReadOnlySpanChar, TValue) |
Tries to get the value associated with the specified key.
|
![]() | TryGetValue(String, TValue) |
Tries to gets the value associated with the specified key.
|
![]() | TryGetValue(StringSegment, TValue) |
Tries to get the value associated with the specified key.
|
Name | Description | |
---|---|---|
![]() | AddRangeKeyValuePairString, TValue | (Defined by CollectionExtensions.) |
![]() | AsThreadSafeKeyValuePairString, TValue |
Returns a LockingCollectionT, which provides a thread-safe wrapper for the specified collection.
This only means that if the members are accessed through the returned LockingCollectionT, then the inner state of the wrapped collection remains always consistent and not that all of the multi-threading concerns can be ignored.
(Defined by CollectionExtensions.)See the Remarks section of the LockingCollectionT class for details and some examples. |
![]() | Convert(Type, CultureInfo) | Overloaded.
Converts an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the generic ConvertTTarget(Object, CultureInfo) overload for an example. |
![]() ![]() | ConvertTTarget(CultureInfo) | Overloaded.
Converts an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Remarks section for details. |
![]() | ForEachKeyValuePairString, TValue |
Similarly to the List<T>.ForEach method, processes an action on each element of an enumerable collection.
(Defined by EnumerableExtensions.) |
![]() | GetRandomElementKeyValuePairString, TValue(Boolean) | Overloaded.
Gets a random element from the enumerable source using a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | GetRandomElementKeyValuePairString, TValue(Random, Boolean) | Overloaded.
Gets a random element from the enumerable source using a specified Random instance.
(Defined by EnumerableExtensions.) |
![]() | In |
Gets whether item is among the elements of set.
(Defined by ObjectExtensions.)See the Examples section of the generic InT(T, T) overload for an example. |
![]() | IndexOf(FuncObject, Boolean) | Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.) |
![]() | IndexOf(Object) | Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.) |
![]() | IndexOfKeyValuePairString, TValue(FuncKeyValuePairString, TValue, Boolean) | Overloaded.
Searches for an element in the source enumeration where the specified predicate returns .
(Defined by EnumerableExtensions.) |
![]() | IndexOfKeyValuePairString, TValue(KeyValuePairString, TValue) | Overloaded.
Searches for an element in the source enumeration.
(Defined by EnumerableExtensions.) |
![]() | IsNullOrEmpty | Overloaded.
Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions.) |
![]() | IsNullOrEmptyKeyValuePairString, TValue | Overloaded.
Determines whether the specified source is or empty (has no elements).
(Defined by EnumerableExtensions.) |
![]() | JoinKeyValuePairString, TValue(Char) | Overloaded.
Concatenates the items of the source collection into a new string instance
using the specified separator between the items.
(Defined by EnumerableExtensions.) |
![]() | JoinKeyValuePairString, TValue(String) | Overloaded.
Concatenates the items of the source collection into a new string instance
using the specified separator between the items.
(Defined by EnumerableExtensions.) |
![]() | ShuffleKeyValuePairString, TValue | Overloaded.
Shuffles an enumerable source (randomizes its elements) using a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleKeyValuePairString, TValue(Guid) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleKeyValuePairString, TValue(Int32) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using the provided seed with a new FastRandom instance.
(Defined by EnumerableExtensions.) |
![]() | ShuffleKeyValuePairString, TValue(Random) | Overloaded.
Shuffles an enumerable source (randomizes its elements) using a specified Random instance.
(Defined by EnumerableExtensions.) |
![]() | ToCircularListKeyValuePairString, TValue |
Creates a CircularListT from an IEnumerableT.
(Defined by EnumerableExtensions.) |
![]() | ToStringKeyedDictionaryKeyValuePairString, TValue(FuncKeyValuePairString, TValue, String, StringSegmentComparer) | Overloaded.
Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified keySelector delegate and a comparer.
(Defined by EnumerableExtensions.) |
![]() | ToStringKeyedDictionaryKeyValuePairString, TValue, TValue(FuncKeyValuePairString, TValue, String, FuncKeyValuePairString, TValue, TValue, StringSegmentComparer) | Overloaded.
Creates a StringKeyedDictionaryTValue from an IEnumerableT instance using the specified key and value selector delegates and a comparer.
(Defined by EnumerableExtensions.) |
![]() | TryAdd(Object, Boolean, Boolean) | Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddKeyValuePairString, TValue(KeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to add the specified item to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddRange(IEnumerable, Boolean, Boolean) | Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryAddRangeKeyValuePairString, TValue(IEnumerableKeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to add the specified collection to the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryClear(Boolean, Boolean) | Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryClearKeyValuePairString, TValue(Boolean, Boolean) | Overloaded.
Tries to remove all elements from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryConvert(Type, Object) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvert(Type, CultureInfo, Object) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired targetType.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvertTTarget(TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryConvertTTarget(CultureInfo, TTarget) | Overloaded.
Tries to convert an Object specified in the obj parameter to the desired TTarget.
(Defined by ObjectExtensions.)See the Examples section of the ConvertTTarget(Object, CultureInfo) method for a related example. |
![]() | TryGetCount(Int32) | Overloaded.
Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions.) |
![]() | TryGetCountKeyValuePairString, TValue(Int32) | Overloaded.
Tries to get the number of elements in the source enumeration without enumerating it.
(Defined by EnumerableExtensions.) |
![]() | TryGetElementAt(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TryGetElementAtKeyValuePairString, TValue(Int32, KeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to get an item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsert(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertKeyValuePairString, TValue(Int32, KeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to insert the specified item at the specified index to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertRange(Int32, IEnumerable, Boolean, Boolean) | Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryInsertRangeKeyValuePairString, TValue(Int32, IEnumerableKeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to insert the specified collection into the target collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemove(Object, Boolean, Boolean) | Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveKeyValuePairString, TValue(KeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to remove the specified item from to the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveAt(Int32, Boolean, Boolean) | Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveAtKeyValuePairString, TValue(Int32, Boolean, Boolean) | Overloaded.
Tries to remove an item at the specified index from the collection.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveRange(Int32, Int32, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.) |
![]() | TryRemoveRangeKeyValuePairString, TValue(Int32, Int32, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the specified collection at the specified index.
(Defined by EnumerableExtensions.) |
![]() | TryReplaceRange(Int32, Int32, IEnumerable, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the target at the specified index, and
to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.) |
![]() | TryReplaceRangeKeyValuePairString, TValue(Int32, Int32, IEnumerableKeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to remove count amount of items from the target at the specified index, and
to insert the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.
(Defined by EnumerableExtensions.) |
![]() | TrySetElementAt(Int32, Object, Boolean, Boolean) | Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
![]() | TrySetElementAtKeyValuePairString, TValue(Int32, KeyValuePairString, TValue, Boolean, Boolean) | Overloaded.
Tries to set the specified item at the specified index in the collection.
(Defined by EnumerableExtensions.) |
Being as a regular IDictionaryTKey, TValue implementation with string key, the StringKeyedDictionaryTValue class can be populated by keys and values as any regular dictionary. However, as it implements also the IStringKeyedDictionaryTValue interface, it allows accessing its values by using StringSegment (supported on every platform) and ReadOnlySpan<char> (in .NET Core 3.0/.NET Standard 2.1 and above) instances.
The StringKeyedDictionaryTValue class uses a custom hashing, which usually makes it faster than a regular DictionaryTKey, TValue with string key.
![]() |
---|
Without specifying a comparer, the StringKeyedDictionaryTValue class does not use randomized hashing for keys no longer than 32 characters. If you want to want to expose a StringKeyedDictionaryTValue to a public service, then make sure you use it with a randomized hash comparer (eg. with OrdinalRandomized). |
Depending on the context, the StringKeyedDictionaryTValue can return either a value type or reference type enumerator. When used in a C# foreach statement directly, the public StringKeyedDictionaryTValueEnumerator type is used, which is a value type (this behavior is similar to the regular DictionaryTKey, TValue class). But when the enumerator is obtained via the IEnumerableT interface (occurs when using LINQ or extension methods), then the StringKeyedDictionaryTValue returns a reference type to avoid boxing and to provide a better performance.
To use custom string comparison you can pass a StringSegmentComparer instance to the constructors. It allows string comparisons by string, StringSegment and ReadOnlySpan<char> instances. By default, the StringKeyedDictionaryTValue uses case-sensitive ordinal comparison.
![]() |
---|
Please note that when using a non-ordinal comparison, then depending on the targeted platform there might occur new string allocations when using query members with StringSegment or ReadOnlySpan<char> parameter values. See the properties and the Create(CultureInfo, Boolean) method of the StringSegmentComparer class for more details. |