Dictionary Routines
22 nodes
On this page 22
Add
FunctionAdds a new entry, throwing System.ArgumentException if the dictionary already has the key, so an accidental duplicate is caught rather than silently overwriting.
Add
dictionary: Dictionary of TKey to TValue
key: TKey
value: TValuevoid Add(
Dictionary<TKey, TValue> dictionary,
TKey key,
TValue value)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The new key; a null key throws System.ArgumentNullException. |
| value | TValue | — | The value to store. |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Add Or Reject Duplicate
FunctionAdds a new entry like DictionaryRoutines.TryAdd, and when the key already exists also gives you a message naming the duplicate key, ready to show or log; the existing entry is left untouched.
AddOrRejectDuplicate -> (result: Truth, error: Text)
dictionary: Dictionary of TKey to TValue
key: TKey
value: TValuebool AddOrRejectDuplicate(
Dictionary<TKey, TValue> dictionary,
TKey key,
TValue value,
out string error)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The new key; a null key throws System.ArgumentNullException. |
| value | TValue | — | The value to store. |
Returns
| result | Truth |
| error | Text |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Add Range
FunctionAdds many key/value pairs at once, in the order given.
AddRange
dictionary: Dictionary of TKey to TValue
items: IEnumerable<KeyValuePair<TKey, TValue>>
overwriteExisting: Truthvoid AddRange(
Dictionary<TKey, TValue> dictionary,
IEnumerable<KeyValuePair<TKey, TValue>> items,
bool overwriteExisting = false)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| items | IEnumerable<KeyValuePair<TKey, TValue>> | — | The pairs to add; must not be null. |
| overwriteExisting | Truth | False | When true, a key that already exists (or repeats within Items) takes the later value. When false, the first such key throws System.ArgumentException, and the pairs added before it stay in the dictionary. |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Capacity
FunctionHow many entries the dictionary can hold before it next has to grow its storage; always at least its count.
Capacity(dictionary: Dictionary of TKey to TValue) -> Integer
int Capacity(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to inspect; must not be null. |
Returns
| result | Integer |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Clear
FunctionRemoves every entry; the dictionary keeps its current capacity, so refilling it does not have to grow it again.
Clear(dictionary: Dictionary of TKey to TValue)
void Clear(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to empty; must not be null. |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Clone
FunctionMakes a new dictionary holding the same entries as Source; adding or removing entries in one afterwards does not affect the other, but the values themselves are not copied, so a value of a reference type is shared by both.
Clone -> Dictionary of TKey to TValue
source: Dictionary of TKey to TValue
comparer: IEqualityComparer<TKey>Dictionary<TKey, TValue> Clone(
Dictionary<TKey, TValue> source,
IEqualityComparer<TKey> comparer)Parameters
| name | type | default | description |
|---|---|---|---|
| source | Dictionary of TKey to TValue | — | The dictionary to copy; must not be null. |
| comparer | IEqualityComparer<TKey> | — | How the copy compares keys; null means the key type's default equality, not the comparer Source uses. If this comparer treats two of the source's keys as the same, System.ArgumentException is thrown. |
Returns
| result | Dictionary of TKey to TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Comparer
FunctionThe comparer the dictionary uses to decide whether two keys are the same, so you can make another dictionary that matches keys the same way.
Comparer(dictionary: Dictionary of TKey to TValue) -> IEqualityComparer<TKey>
IEqualityComparer<TKey> Comparer(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to inspect; must not be null. |
Returns
| result | IEqualityComparer<TKey> |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Contains Key
FunctionWhether the dictionary has an entry for Key, matched with the dictionary's key comparer.
ContainsKey -> Truth
dictionary: Dictionary of TKey to TValue
key: TKeybool ContainsKey(Dictionary<TKey, TValue> dictionary, TKey key)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to search; must not be null. |
| key | TKey | — | The key to look for; a null key throws System.ArgumentNullException. |
Returns
| result | Truth |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Contains Value
FunctionWhether any entry has Value as its value, compared with the value type's default equality.
ContainsValue -> Truth
dictionary: Dictionary of TKey to TValue
value: TValuebool ContainsValue(
Dictionary<TKey, TValue> dictionary,
TValue value)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to search; must not be null. |
| value | TValue | — | The value to look for; may be null. |
Returns
| result | Truth |
Remarks
Unlike a key lookup this checks every entry in turn, so it gets slower as the dictionary grows.
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Count
FunctionHow many key/value pairs the dictionary holds.
Count(dictionary: Dictionary of TKey to TValue) -> Integer
int Count(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to measure; must not be null. |
Returns
| result | Integer |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Create
FunctionOverload 1 of 4
Create() -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create()
Makes a new, empty dictionary whose keys are compared with the key type's default equality.
Returns
| result | Dictionary of TKey to TValue |
Overload 2 of 4
Create(capacity: Integer) -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create(int capacity)
Makes a new, empty dictionary with room reserved for at least Capacity entries, so it does not have to grow while you fill it; use it when you know roughly how many entries are coming.
Parameters
| name | type | default | description |
|---|---|---|---|
| capacity | Integer | — | How many entries to reserve room for; a negative number throws System.ArgumentOutOfRangeException. |
Returns
| result | Dictionary of TKey to TValue |
Overload 3 of 4
Create(comparer: IEqualityComparer<TKey>) -> Dictionary of TKey to TValue
Dictionary<TKey, TValue> Create(IEqualityComparer<TKey> comparer)
Makes a new, empty dictionary that uses Comparer to decide whether two keys are the same, for example StringComparer.OrdinalIgnoreCase for case-insensitive text keys.
Parameters
| name | type | default | description |
|---|---|---|---|
| comparer | IEqualityComparer<TKey> | — | How keys are compared; null means the key type's default equality. |
Returns
| result | Dictionary of TKey to TValue |
Overload 4 of 4
Create -> Dictionary of TKey to TValue
capacity: Integer
comparer: IEqualityComparer<TKey>Dictionary<TKey, TValue> Create(
int capacity,
IEqualityComparer<TKey> comparer)Makes a new, empty dictionary with room reserved for at least Capacity entries and keys compared by Comparer.
Parameters
| name | type | default | description |
|---|---|---|---|
| capacity | Integer | — | How many entries to reserve room for; a negative number throws System.ArgumentOutOfRangeException. |
| comparer | IEqualityComparer<TKey> | — | How keys are compared; null means the key type's default equality. |
Returns
| result | Dictionary of TKey to TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Ensure Capacity
FunctionGrows the dictionary's storage, if needed, so it can hold at least Capacity entries without growing again; it never shrinks it.
EnsureCapacity -> Integer
dictionary: Dictionary of TKey to TValue
capacity: Integerint EnsureCapacity(
Dictionary<TKey, TValue> dictionary,
int capacity)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| capacity | Integer | — | The number of entries to make room for; a negative number throws System.ArgumentOutOfRangeException. |
Returns
| result | Integer |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Get
FunctionThe value stored under Key; use it when the key must be there, and DictionaryRoutines.GetOrDefault or DictionaryRoutines.TryGet when it may not be.
Get -> TValue
dictionary: Dictionary of TKey to TValue
key: TKeyTValue Get(Dictionary<TKey, TValue> dictionary, TKey key)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to read; must not be null. |
| key | TKey | — | The key to look up; a missing key throws Generic.KeyNotFoundException and a null key throws System.ArgumentNullException. |
Returns
| Result | TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Get Or Default
FunctionThe value stored under Key, or Default Value when the dictionary has no such key.
GetOrDefault -> TValue
dictionary: Dictionary of TKey to TValue
key: TKey
defaultValue: TValueTValue GetOrDefault(
Dictionary<TKey, TValue> dictionary,
TKey key,
TValue defaultValue)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to read; must not be null. |
| key | TKey | — | The key to look up; a null key throws System.ArgumentNullException. |
| defaultValue | TValue | — | What to answer when the key is missing; when omitted, the value type's default (0, false or null). |
Returns
| Result | TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Keys
FunctionThe dictionary's keys, in no guaranteed order.
Keys(dictionary: Dictionary of TKey to TValue) -> Dictionary<TKey, TValue>.KeyCollection
Dictionary<TKey, TValue>.KeyCollection Keys(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to read; must not be null. |
Returns
| result | Dictionary<TKey, TValue>.KeyCollection |
Remarks
This is a live view rather than a copy: it reflects later additions and removals, and enumerating it while the dictionary is changed throws System.InvalidOperationException. Use DictionaryRoutines.ToArray for a snapshot.
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Remove
FunctionOverload 1 of 2
Remove -> Truth
dictionary: Dictionary of TKey to TValue
key: TKeybool Remove(Dictionary<TKey, TValue> dictionary, TKey key)
Removes the entry for Key, if there is one.
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The key to remove; a null key throws System.ArgumentNullException. |
Returns
| result | Truth |
Overload 2 of 2
Remove -> (result: Truth, value: TValue)
dictionary: Dictionary of TKey to TValue
key: TKeybool Remove(
Dictionary<TKey, TValue> dictionary,
TKey key,
out TValue value)Removes the entry for Key and hands back the value it held, so you can take an item out and use it in one step.
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The key to remove; a null key throws System.ArgumentNullException. |
Returns
| result | Truth |
| value | TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Set
FunctionStores Value under Key, adding a new entry or replacing the value already there; use DictionaryRoutines.Add instead when a duplicate key should be an error.
Set
dictionary: Dictionary of TKey to TValue
key: TKey
value: TValuevoid Set(
Dictionary<TKey, TValue> dictionary,
TKey key,
TValue value)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The key to store under; a null key throws System.ArgumentNullException. |
| value | TValue | — | The value to store. |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
To Array
FunctionCopies every key/value pair into a new array, a snapshot that later changes to the dictionary do not affect.
ToArray(dictionary: Dictionary of TKey to TValue) -> KeyValuePair<TKey, TValue> Array
KeyValuePair<TKey, TValue>[] ToArray(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to copy; must not be null. |
Returns
| result | KeyValuePair<TKey, TValue> Array |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Trim Excess
FunctionOverload 1 of 2
TrimExcess(dictionary: Dictionary of TKey to TValue)
void TrimExcess(Dictionary<TKey, TValue> dictionary)
Shrinks the dictionary's storage to fit the entries it holds now, giving back memory after many removals.
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
Overload 2 of 2
TrimExcess
dictionary: Dictionary of TKey to TValue
capacity: Integervoid TrimExcess(
Dictionary<TKey, TValue> dictionary,
int capacity)Shrinks the dictionary's storage to fit Capacity entries, leaving room to grow to that size without reallocating.
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| capacity | Integer | — | The number of entries to keep room for; less than the current count throws System.ArgumentOutOfRangeException. |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Try Add
FunctionAdds a new entry only if the key is not already there; an existing entry is left untouched.
TryAdd -> Truth
dictionary: Dictionary of TKey to TValue
key: TKey
value: TValuebool TryAdd(
Dictionary<TKey, TValue> dictionary,
TKey key,
TValue value)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to change; must not be null. |
| key | TKey | — | The new key; a null key throws System.ArgumentNullException. |
| value | TValue | — | The value to store. |
Returns
| result | Truth |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Try Get
FunctionLooks up Key without failing when it is missing, telling you both whether it was found and what it holds.
TryGet -> (result: Truth, value: TValue)
dictionary: Dictionary of TKey to TValue
key: TKeybool TryGet(
Dictionary<TKey, TValue> dictionary,
TKey key,
out TValue value)Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to read; must not be null. |
| key | TKey | — | The key to look up; a null key throws System.ArgumentNullException. |
Returns
| result | Truth |
| value | TValue |
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library
Values
FunctionThe dictionary's values, in the same order as DictionaryRoutines.Keys.
Values(dictionary: Dictionary of TKey to TValue) -> Dictionary<TKey, TValue>.ValueCollection
Dictionary<TKey, TValue>.ValueCollection Values(Dictionary<TKey, TValue> dictionary)
Parameters
| name | type | default | description |
|---|---|---|---|
| dictionary | Dictionary of TKey to TValue | — | The dictionary to read; must not be null. |
Returns
| result | Dictionary<TKey, TValue>.ValueCollection |
Remarks
This is a live view rather than a copy: it reflects later changes, and enumerating it while the dictionary is changed throws System.InvalidOperationException.
- Ships with
- Divooka ExploreDivooka Compute
- Graph kinds
- Flows Function Events Routine Constructs StateMachineState
- Declared by
- Dictionary Routines
- Package
- Standard Library