Class Dictionary
- Namespace
- Godot.Collections
- Assembly
- GodotSharp.dll
Wrapper around Godot's Dictionary class, a dictionary of Variant typed elements allocated in the engine in C++. Useful when interfacing with the engine.
public sealed class Dictionary : IDictionary<Variant, Variant>, ICollection<KeyValuePair<Variant, Variant>>, IReadOnlyDictionary<Variant, Variant>, IReadOnlyCollection<KeyValuePair<Variant, Variant>>, IEnumerable<KeyValuePair<Variant, Variant>>, IEnumerable, IDisposable
- Inheritance
-
Dictionary
- Implements
- Inherited Members
Constructors
Dictionary()
Constructs a new empty Dictionary.
public Dictionary()
Properties
Count
Returns the number of elements in this Dictionary. This is also known as the size or length of the dictionary.
public int Count { get; }
Property Value
- int
The number of elements.
IsReadOnly
Returns true if the dictionary is read-only. See MakeReadOnly().
public bool IsReadOnly { get; }
Property Value
this[Variant]
Returns the value at the given key
.
public Variant this[Variant key] { get; set; }
Parameters
key
Variant
Property Value
- Variant
The value at the given
key
.
Exceptions
- InvalidOperationException
The property is assigned and the dictionary is read-only.
- KeyNotFoundException
The property is retrieved and an entry for
key
does not exist in the dictionary.
Keys
Gets the collection of keys in this Dictionary.
public ICollection<Variant> Keys { get; }
Property Value
Values
Gets the collection of elements in this Dictionary.
public ICollection<Variant> Values { get; }
Property Value
Methods
Add(Variant, Variant)
Adds an value value
at key key
to this Dictionary.
public void Add(Variant key, Variant value)
Parameters
Exceptions
- InvalidOperationException
The dictionary is read-only.
- ArgumentException
An entry for
key
already exists in the dictionary.
Clear()
Clears the dictionary, removing all entries from it.
public void Clear()
Exceptions
- InvalidOperationException
The dictionary is read-only.
ContainsKey(Variant)
Checks if this Dictionary contains the given key.
public bool ContainsKey(Variant key)
Parameters
key
VariantThe key to look for.
Returns
- bool
Whether or not this dictionary contains the given key.
Dispose()
Disposes of this Dictionary.
public void Dispose()
Dispose(bool)
public void Dispose(bool disposing)
Parameters
disposing
bool
Duplicate(bool)
Returns a copy of the Dictionary.
If deep
is true, a deep copy is performed:
all nested arrays and dictionaries are duplicated and will not be shared with
the original dictionary. If false, a shallow copy is made and
references to the original nested arrays and dictionaries are kept, so that
modifying a sub-array or dictionary in the copy will also impact those
referenced in the source dictionary. Note that any GodotObject derived
elements will be shallow copied regardless of the deep
setting.
public Dictionary Duplicate(bool deep = false)
Parameters
Returns
- Dictionary
A new Godot Dictionary.
~Dictionary()
protected ~Dictionary()
GetEnumerator()
Gets an enumerator for this Dictionary.
public IEnumerator<KeyValuePair<Variant, Variant>> GetEnumerator()
Returns
- IEnumerator<KeyValuePair<Variant, Variant>>
An enumerator.
MakeReadOnly()
Makes the Dictionary read-only, i.e. disabled modying of the dictionary's elements. Does not apply to nested content, e.g. content of nested dictionaries.
public void MakeReadOnly()
Merge(Dictionary, bool)
Adds entries from dictionary
to this dictionary.
By default, duplicate keys are not copied over, unless overwrite
is true.
public void Merge(Dictionary dictionary, bool overwrite = false)
Parameters
dictionary
DictionaryDictionary to copy entries from.
overwrite
boolIf duplicate keys should be copied over as well.
Exceptions
- InvalidOperationException
The dictionary is read-only.
RecursiveEqual(Dictionary)
Compares this Dictionary against the other
Dictionary recursively. Returns true if the
two dictionaries contain the same keys and values. The order of the entries
does not matter.
otherwise.
public bool RecursiveEqual(Dictionary other)
Parameters
other
DictionaryThe other dictionary to compare against.
Returns
Remove(Variant)
Removes an element from this Dictionary by key.
public bool Remove(Variant key)
Parameters
key
VariantThe key of the element to remove.
Returns
Exceptions
- InvalidOperationException
The dictionary is read-only.
ToString()
Converts this Dictionary to a string.
public override string ToString()
Returns
- string
A string representation of this dictionary.
TryGetValue(Variant, out Variant)
Gets the value for the given key
in the dictionary.
Returns true if an entry for the given key exists in
the dictionary; otherwise, returns false.
public bool TryGetValue(Variant key, out Variant value)
Parameters
Returns
- bool
If an entry was found for the given
key
.