2
0

class_dictionary.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Dictionary.xml.
  6. .. _class_Dictionary:
  7. Dictionary
  8. ==========
  9. A built-in data structure that holds key-value pairs.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. Dictionaries are associative containers that contain values referenced by unique keys. Dictionaries will preserve the insertion order when adding new entries. In other programming languages, this data structure is often referred to as a hash map or an associative array.
  14. You can define a dictionary by placing a comma-separated list of ``key: value`` pairs inside curly braces ``{}``.
  15. Creating a dictionary:
  16. .. tabs::
  17. .. code-tab:: gdscript
  18. var my_dict = {} # Creates an empty dictionary.
  19. var dict_variable_key = "Another key name"
  20. var dict_variable_value = "value2"
  21. var another_dict = {
  22. "Some key name": "value1",
  23. dict_variable_key: dict_variable_value,
  24. }
  25. var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
  26. # Alternative Lua-style syntax.
  27. # Doesn't require quotes around keys, but only string constants can be used as key names.
  28. # Additionally, key names must start with a letter or an underscore.
  29. # Here, `some_key` is a string literal, not a variable!
  30. another_dict = {
  31. some_key = 42,
  32. }
  33. .. code-tab:: csharp
  34. var myDict = new Godot.Collections.Dictionary(); // Creates an empty dictionary.
  35. var pointsDict = new Godot.Collections.Dictionary
  36. {
  37. {"White", 50},
  38. {"Yellow", 75},
  39. {"Orange", 100}
  40. };
  41. You can access a dictionary's value by referencing its corresponding key. In the above example, ``points_dict["White"]`` will return ``50``. You can also write ``points_dict.White``, which is equivalent. However, you'll have to use the bracket syntax if the key you're accessing the dictionary with isn't a fixed string (such as a number or variable).
  42. .. tabs::
  43. .. code-tab:: gdscript
  44. @export_enum("White", "Yellow", "Orange") var my_color: String
  45. var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
  46. func _ready():
  47. # We can't use dot syntax here as `my_color` is a variable.
  48. var points = points_dict[my_color]
  49. .. code-tab:: csharp
  50. [Export(PropertyHint.Enum, "White,Yellow,Orange")]
  51. public string MyColor { get; set; }
  52. private Godot.Collections.Dictionary _pointsDict = new Godot.Collections.Dictionary
  53. {
  54. {"White", 50},
  55. {"Yellow", 75},
  56. {"Orange", 100}
  57. };
  58. public override void _Ready()
  59. {
  60. int points = (int)_pointsDict[MyColor];
  61. }
  62. In the above code, ``points`` will be assigned the value that is paired with the appropriate color selected in ``my_color``.
  63. Dictionaries can contain more complex data:
  64. .. tabs::
  65. .. code-tab:: gdscript
  66. var my_dict = {
  67. "First Array": [1, 2, 3, 4] # Assigns an Array to a String key.
  68. }
  69. .. code-tab:: csharp
  70. var myDict = new Godot.Collections.Dictionary
  71. {
  72. {"First Array", new Godot.Collections.Array{1, 2, 3, 4}}
  73. };
  74. To add a key to an existing dictionary, access it like an existing key and assign to it:
  75. .. tabs::
  76. .. code-tab:: gdscript
  77. var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
  78. points_dict["Blue"] = 150 # Add "Blue" as a key and assign 150 as its value.
  79. .. code-tab:: csharp
  80. var pointsDict = new Godot.Collections.Dictionary
  81. {
  82. {"White", 50},
  83. {"Yellow", 75},
  84. {"Orange", 100}
  85. };
  86. pointsDict["Blue"] = 150; // Add "Blue" as a key and assign 150 as its value.
  87. Finally, dictionaries can contain different types of keys and values in the same dictionary:
  88. .. tabs::
  89. .. code-tab:: gdscript
  90. # This is a valid dictionary.
  91. # To access the string "Nested value" below, use `my_dict.sub_dict.sub_key` or `my_dict["sub_dict"]["sub_key"]`.
  92. # Indexing styles can be mixed and matched depending on your needs.
  93. var my_dict = {
  94. "String Key": 5,
  95. 4: [1, 2, 3],
  96. 7: "Hello",
  97. "sub_dict": {"sub_key": "Nested value"},
  98. }
  99. .. code-tab:: csharp
  100. // This is a valid dictionary.
  101. // To access the string "Nested value" below, use `((Godot.Collections.Dictionary)myDict["sub_dict"])["sub_key"]`.
  102. var myDict = new Godot.Collections.Dictionary {
  103. {"String Key", 5},
  104. {4, new Godot.Collections.Array{1,2,3}},
  105. {7, "Hello"},
  106. {"sub_dict", new Godot.Collections.Dictionary{{"sub_key", "Nested value"}}}
  107. };
  108. The keys of a dictionary can be iterated with the ``for`` keyword:
  109. .. tabs::
  110. .. code-tab:: gdscript
  111. var groceries = {"Orange": 20, "Apple": 2, "Banana": 4}
  112. for fruit in groceries:
  113. var amount = groceries[fruit]
  114. .. code-tab:: csharp
  115. var groceries = new Godot.Collections.Dictionary{{"Orange", 20}, {"Apple", 2}, {"Banana", 4}};
  116. foreach (var (fruit, amount) in groceries)
  117. {
  118. // `fruit` is the key, `amount` is the value.
  119. }
  120. \ **Note:** Dictionaries are always passed by reference. To get a copy of a dictionary which can be modified independently of the original dictionary, use :ref:`duplicate<class_Dictionary_method_duplicate>`.
  121. \ **Note:** Erasing elements while iterating over dictionaries is **not** supported and will result in unpredictable behavior.
  122. .. note::
  123. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  124. .. rst-class:: classref-introduction-group
  125. Tutorials
  126. ---------
  127. - `GDScript basics: Dictionary <../tutorials/scripting/gdscript/gdscript_basics.html#dictionary>`__
  128. - `3D Voxel Demo <https://godotengine.org/asset-library/asset/676>`__
  129. - `OS Test Demo <https://godotengine.org/asset-library/asset/677>`__
  130. .. rst-class:: classref-reftable-group
  131. Constructors
  132. ------------
  133. .. table::
  134. :widths: auto
  135. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------+
  136. | :ref:`Dictionary<class_Dictionary>` | :ref:`Dictionary<class_Dictionary_constructor_Dictionary>` **(** **)** |
  137. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------+
  138. | :ref:`Dictionary<class_Dictionary>` | :ref:`Dictionary<class_Dictionary_constructor_Dictionary>` **(** :ref:`Dictionary<class_Dictionary>` from **)** |
  139. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------+
  140. .. rst-class:: classref-reftable-group
  141. Methods
  142. -------
  143. .. table::
  144. :widths: auto
  145. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | void | :ref:`clear<class_Dictionary_method_clear>` **(** **)** |
  147. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`Dictionary<class_Dictionary>` | :ref:`duplicate<class_Dictionary_method_duplicate>` **(** :ref:`bool<class_bool>` deep=false **)** |const| |
  149. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`bool<class_bool>` | :ref:`erase<class_Dictionary_method_erase>` **(** :ref:`Variant<class_Variant>` key **)** |
  151. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`Variant<class_Variant>` | :ref:`find_key<class_Dictionary_method_find_key>` **(** :ref:`Variant<class_Variant>` value **)** |const| |
  153. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`Variant<class_Variant>` | :ref:`get<class_Dictionary_method_get>` **(** :ref:`Variant<class_Variant>` key, :ref:`Variant<class_Variant>` default=null **)** |const| |
  155. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`Variant<class_Variant>` | :ref:`get_or_add<class_Dictionary_method_get_or_add>` **(** :ref:`Variant<class_Variant>` key, :ref:`Variant<class_Variant>` default=null **)** |
  157. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`bool<class_bool>` | :ref:`has<class_Dictionary_method_has>` **(** :ref:`Variant<class_Variant>` key **)** |const| |
  159. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`bool<class_bool>` | :ref:`has_all<class_Dictionary_method_has_all>` **(** :ref:`Array<class_Array>` keys **)** |const| |
  161. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`int<class_int>` | :ref:`hash<class_Dictionary_method_hash>` **(** **)** |const| |
  163. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`bool<class_bool>` | :ref:`is_empty<class_Dictionary_method_is_empty>` **(** **)** |const| |
  165. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`bool<class_bool>` | :ref:`is_read_only<class_Dictionary_method_is_read_only>` **(** **)** |const| |
  167. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`Array<class_Array>` | :ref:`keys<class_Dictionary_method_keys>` **(** **)** |const| |
  169. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | void | :ref:`make_read_only<class_Dictionary_method_make_read_only>` **(** **)** |
  171. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | void | :ref:`merge<class_Dictionary_method_merge>` **(** :ref:`Dictionary<class_Dictionary>` dictionary, :ref:`bool<class_bool>` overwrite=false **)** |
  173. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`int<class_int>` | :ref:`size<class_Dictionary_method_size>` **(** **)** |const| |
  175. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`Array<class_Array>` | :ref:`values<class_Dictionary_method_values>` **(** **)** |const| |
  177. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  178. .. rst-class:: classref-reftable-group
  179. Operators
  180. ---------
  181. .. table::
  182. :widths: auto
  183. +-------------------------------+--------------------------------------------------------------------------------------------------------------------+
  184. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Dictionary_operator_neq_Dictionary>` **(** :ref:`Dictionary<class_Dictionary>` right **)** |
  185. +-------------------------------+--------------------------------------------------------------------------------------------------------------------+
  186. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Dictionary_operator_eq_Dictionary>` **(** :ref:`Dictionary<class_Dictionary>` right **)** |
  187. +-------------------------------+--------------------------------------------------------------------------------------------------------------------+
  188. | :ref:`Variant<class_Variant>` | :ref:`operator []<class_Dictionary_operator_idx_Variant>` **(** :ref:`Variant<class_Variant>` key **)** |
  189. +-------------------------------+--------------------------------------------------------------------------------------------------------------------+
  190. .. rst-class:: classref-section-separator
  191. ----
  192. .. rst-class:: classref-descriptions-group
  193. Constructor Descriptions
  194. ------------------------
  195. .. _class_Dictionary_constructor_Dictionary:
  196. .. rst-class:: classref-constructor
  197. :ref:`Dictionary<class_Dictionary>` **Dictionary** **(** **)**
  198. Constructs an empty **Dictionary**.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. rst-class:: classref-constructor
  202. :ref:`Dictionary<class_Dictionary>` **Dictionary** **(** :ref:`Dictionary<class_Dictionary>` from **)**
  203. Returns the same dictionary as ``from``. If you need a copy of the dictionary, use :ref:`duplicate<class_Dictionary_method_duplicate>`.
  204. .. rst-class:: classref-section-separator
  205. ----
  206. .. rst-class:: classref-descriptions-group
  207. Method Descriptions
  208. -------------------
  209. .. _class_Dictionary_method_clear:
  210. .. rst-class:: classref-method
  211. void **clear** **(** **)**
  212. Clears the dictionary, removing all entries from it.
  213. .. rst-class:: classref-item-separator
  214. ----
  215. .. _class_Dictionary_method_duplicate:
  216. .. rst-class:: classref-method
  217. :ref:`Dictionary<class_Dictionary>` **duplicate** **(** :ref:`bool<class_bool>` deep=false **)** |const|
  218. Creates and returns a new copy of the dictionary. If ``deep`` is ``true``, inner **Dictionary** and :ref:`Array<class_Array>` keys and values are also copied, recursively.
  219. .. rst-class:: classref-item-separator
  220. ----
  221. .. _class_Dictionary_method_erase:
  222. .. rst-class:: classref-method
  223. :ref:`bool<class_bool>` **erase** **(** :ref:`Variant<class_Variant>` key **)**
  224. Removes the dictionary entry by key, if it exists. Returns ``true`` if the given ``key`` existed in the dictionary, otherwise ``false``.
  225. \ **Note:** Do not erase entries while iterating over the dictionary. You can iterate over the :ref:`keys<class_Dictionary_method_keys>` array instead.
  226. .. rst-class:: classref-item-separator
  227. ----
  228. .. _class_Dictionary_method_find_key:
  229. .. rst-class:: classref-method
  230. :ref:`Variant<class_Variant>` **find_key** **(** :ref:`Variant<class_Variant>` value **)** |const|
  231. Finds and returns the first key whose associated value is equal to ``value``, or ``null`` if it is not found.
  232. \ **Note:** ``null`` is also a valid key. If inside the dictionary, :ref:`find_key<class_Dictionary_method_find_key>` may give misleading results.
  233. .. rst-class:: classref-item-separator
  234. ----
  235. .. _class_Dictionary_method_get:
  236. .. rst-class:: classref-method
  237. :ref:`Variant<class_Variant>` **get** **(** :ref:`Variant<class_Variant>` key, :ref:`Variant<class_Variant>` default=null **)** |const|
  238. Returns the corresponding value for the given ``key`` in the dictionary. If the ``key`` does not exist, returns ``default``, or ``null`` if the parameter is omitted.
  239. .. rst-class:: classref-item-separator
  240. ----
  241. .. _class_Dictionary_method_get_or_add:
  242. .. rst-class:: classref-method
  243. :ref:`Variant<class_Variant>` **get_or_add** **(** :ref:`Variant<class_Variant>` key, :ref:`Variant<class_Variant>` default=null **)**
  244. Gets a value and ensures the key is set. If the ``key`` exists in the dictionary, this behaves like :ref:`get<class_Dictionary_method_get>`. Otherwise, the ``default`` value is inserted into the dictionary and returned.
  245. .. rst-class:: classref-item-separator
  246. ----
  247. .. _class_Dictionary_method_has:
  248. .. rst-class:: classref-method
  249. :ref:`bool<class_bool>` **has** **(** :ref:`Variant<class_Variant>` key **)** |const|
  250. Returns ``true`` if the dictionary contains an entry with the given ``key``.
  251. .. tabs::
  252. .. code-tab:: gdscript
  253. var my_dict = {
  254. "Godot" : 4,
  255. 210 : null,
  256. }
  257. print(my_dict.has("Godot")) # Prints true
  258. print(my_dict.has(210)) # Prints true
  259. print(my_dict.has(4)) # Prints false
  260. .. code-tab:: csharp
  261. var myDict = new Godot.Collections.Dictionary
  262. {
  263. { "Godot", 4 },
  264. { 210, default },
  265. };
  266. GD.Print(myDict.ContainsKey("Godot")); // Prints true
  267. GD.Print(myDict.ContainsKey(210)); // Prints true
  268. GD.Print(myDict.ContainsKey(4)); // Prints false
  269. In GDScript, this is equivalent to the ``in`` operator:
  270. ::
  271. if "Godot" in {"Godot": 4}:
  272. print("The key is here!") # Will be printed.
  273. \ **Note:** This method returns ``true`` as long as the ``key`` exists, even if its corresponding value is ``null``.
  274. .. rst-class:: classref-item-separator
  275. ----
  276. .. _class_Dictionary_method_has_all:
  277. .. rst-class:: classref-method
  278. :ref:`bool<class_bool>` **has_all** **(** :ref:`Array<class_Array>` keys **)** |const|
  279. Returns ``true`` if the dictionary contains all keys in the given ``keys`` array.
  280. ::
  281. var data = {"width" : 10, "height" : 20}
  282. data.has_all(["height", "width"]) # Returns true
  283. .. rst-class:: classref-item-separator
  284. ----
  285. .. _class_Dictionary_method_hash:
  286. .. rst-class:: classref-method
  287. :ref:`int<class_int>` **hash** **(** **)** |const|
  288. Returns a hashed 32-bit integer value representing the dictionary contents.
  289. .. tabs::
  290. .. code-tab:: gdscript
  291. var dict1 = {"A": 10, "B": 2}
  292. var dict2 = {"A": 10, "B": 2}
  293. print(dict1.hash() == dict2.hash()) # Prints true
  294. .. code-tab:: csharp
  295. var dict1 = new Godot.Collections.Dictionary{{"A", 10}, {"B", 2}};
  296. var dict2 = new Godot.Collections.Dictionary{{"A", 10}, {"B", 2}};
  297. // Godot.Collections.Dictionary has no Hash() method. Use GD.Hash() instead.
  298. GD.Print(GD.Hash(dict1) == GD.Hash(dict2)); // Prints true
  299. \ **Note:** Dictionaries with the same entries but in a different order will not have the same hash.
  300. \ **Note:** Dictionaries with equal hash values are *not* guaranteed to be the same, because of hash collisions. On the contrary, dictionaries with different hash values are guaranteed to be different.
  301. .. rst-class:: classref-item-separator
  302. ----
  303. .. _class_Dictionary_method_is_empty:
  304. .. rst-class:: classref-method
  305. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  306. Returns ``true`` if the dictionary is empty (its size is ``0``). See also :ref:`size<class_Dictionary_method_size>`.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_Dictionary_method_is_read_only:
  310. .. rst-class:: classref-method
  311. :ref:`bool<class_bool>` **is_read_only** **(** **)** |const|
  312. Returns ``true`` if the dictionary is read-only. See :ref:`make_read_only<class_Dictionary_method_make_read_only>`. Dictionaries are automatically read-only if declared with ``const`` keyword.
  313. .. rst-class:: classref-item-separator
  314. ----
  315. .. _class_Dictionary_method_keys:
  316. .. rst-class:: classref-method
  317. :ref:`Array<class_Array>` **keys** **(** **)** |const|
  318. Returns the list of keys in the dictionary.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_Dictionary_method_make_read_only:
  322. .. rst-class:: classref-method
  323. void **make_read_only** **(** **)**
  324. Makes the dictionary read-only, i.e. disables modification of the dictionary's contents. Does not apply to nested content, e.g. content of nested dictionaries.
  325. .. rst-class:: classref-item-separator
  326. ----
  327. .. _class_Dictionary_method_merge:
  328. .. rst-class:: classref-method
  329. void **merge** **(** :ref:`Dictionary<class_Dictionary>` dictionary, :ref:`bool<class_bool>` overwrite=false **)**
  330. Adds entries from ``dictionary`` to this dictionary. By default, duplicate keys are not copied over, unless ``overwrite`` is ``true``.
  331. .. tabs::
  332. .. code-tab:: gdscript
  333. var dict = { "item": "sword", "quantity": 2 }
  334. var other_dict = { "quantity": 15, "color": "silver" }
  335. # Overwriting of existing keys is disabled by default.
  336. dict.merge(other_dict)
  337. print(dict) # { "item": "sword", "quantity": 2, "color": "silver" }
  338. # With overwriting of existing keys enabled.
  339. dict.merge(other_dict, true)
  340. print(dict) # { "item": "sword", "quantity": 15, "color": "silver" }
  341. .. code-tab:: csharp
  342. var dict = new Godot.Collections.Dictionary
  343. {
  344. ["item"] = "sword",
  345. ["quantity"] = 2,
  346. };
  347. var otherDict = new Godot.Collections.Dictionary
  348. {
  349. ["quantity"] = 15,
  350. ["color"] = "silver",
  351. };
  352. // Overwriting of existing keys is disabled by default.
  353. dict.Merge(otherDict);
  354. GD.Print(dict); // { "item": "sword", "quantity": 2, "color": "silver" }
  355. // With overwriting of existing keys enabled.
  356. dict.Merge(otherDict, true);
  357. GD.Print(dict); // { "item": "sword", "quantity": 15, "color": "silver" }
  358. \ **Note:** :ref:`merge<class_Dictionary_method_merge>` is *not* recursive. Nested dictionaries are considered as keys that can be overwritten or not depending on the value of ``overwrite``, but they will never be merged together.
  359. .. rst-class:: classref-item-separator
  360. ----
  361. .. _class_Dictionary_method_size:
  362. .. rst-class:: classref-method
  363. :ref:`int<class_int>` **size** **(** **)** |const|
  364. Returns the number of entries in the dictionary. Empty dictionaries (``{ }``) always return ``0``. See also :ref:`is_empty<class_Dictionary_method_is_empty>`.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_Dictionary_method_values:
  368. .. rst-class:: classref-method
  369. :ref:`Array<class_Array>` **values** **(** **)** |const|
  370. Returns the list of values in this dictionary.
  371. .. rst-class:: classref-section-separator
  372. ----
  373. .. rst-class:: classref-descriptions-group
  374. Operator Descriptions
  375. ---------------------
  376. .. _class_Dictionary_operator_neq_Dictionary:
  377. .. rst-class:: classref-operator
  378. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Dictionary<class_Dictionary>` right **)**
  379. Returns ``true`` if the two dictionaries do not contain the same keys and values.
  380. .. rst-class:: classref-item-separator
  381. ----
  382. .. _class_Dictionary_operator_eq_Dictionary:
  383. .. rst-class:: classref-operator
  384. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Dictionary<class_Dictionary>` right **)**
  385. Returns ``true`` if the two dictionaries contain the same keys and values. The order of the entries does not matter.
  386. \ **Note:** In C#, by convention, this operator compares by **reference**. If you need to compare by value, iterate over both dictionaries.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_Dictionary_operator_idx_Variant:
  390. .. rst-class:: classref-operator
  391. :ref:`Variant<class_Variant>` **operator []** **(** :ref:`Variant<class_Variant>` key **)**
  392. Returns the corresponding value for the given ``key`` in the dictionary. If the entry does not exist, fails and returns ``null``. For safe access, use :ref:`get<class_Dictionary_method_get>` or :ref:`has<class_Dictionary_method_has>`.
  393. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  394. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  395. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  396. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  397. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  398. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  399. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`