c_sharp_differences.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. .. _doc_c_sharp_differences:
  2. C# API differences to GDScript
  3. ==============================
  4. This is a (incomplete) list of API differences between C# and GDScript.
  5. General differences
  6. -------------------
  7. As explained in the :ref:`doc_c_sharp`, C# generally uses ``PascalCase`` instead
  8. of the ``snake_case`` used in GDScript and C++.
  9. Global scope
  10. ------------
  11. Global functions and some constants had to be moved to classes, since C#
  12. does not allow declaring them in namespaces.
  13. Most global constants were moved to their own enums.
  14. Constants
  15. ^^^^^^^^^
  16. In C#, only primitive types can be constant. For example, the ``TAU`` constant
  17. is replaced by the ``Mathf.Tau`` constant, but the ``Vector2.RIGHT`` constant
  18. is replaced by the ``Vector2.Right`` read-only property. This behaves similarly
  19. to a constant, but can't be used in some contexts like ``switch`` statements.
  20. Global enum constants were moved to their own enums.
  21. For example, ``ERR_*`` constants were moved to the ``Error`` enum.
  22. Special cases:
  23. ======================= ===========================================================
  24. GDScript C#
  25. ======================= ===========================================================
  26. ``SPKEY`` ``GD.SpKey``
  27. ``TYPE_*`` ``Variant.Type`` enum
  28. ``OP_*`` ``Variant.Operator`` enum
  29. ======================= ===========================================================
  30. Math functions
  31. ^^^^^^^^^^^^^^
  32. Math global functions, like ``abs``, ``acos``, ``asin``, ``atan`` and ``atan2``, are
  33. located under ``Mathf`` as ``Abs``, ``Acos``, ``Asin``, ``Atan`` and ``Atan2``.
  34. The ``PI`` constant can be found as ``Mathf.Pi``.
  35. Random functions
  36. ^^^^^^^^^^^^^^^^
  37. Random global functions, like ``rand_range`` and ``rand_seed``, are located under ``GD``.
  38. Example: ``GD.RandRange`` and ``GD.RandSeed``.
  39. Other functions
  40. ^^^^^^^^^^^^^^^
  41. Many other global functions like ``print`` and ``var2str`` are located under ``GD``.
  42. Example: ``GD.Print`` and ``GD.Var2Str``.
  43. Exceptions:
  44. =========================== =======================================================
  45. GDScript C#
  46. =========================== =======================================================
  47. ``weakref(obj)`` ``Object.WeakRef(obj)``
  48. ``is_instance_valid(obj)`` ``Object.IsInstanceValid(obj)``
  49. =========================== =======================================================
  50. Tips
  51. ^^^^
  52. Sometimes it can be useful to use the ``using static`` directive. This directive allows
  53. to access the members and nested types of a class without specifying the class name.
  54. Example:
  55. .. code-block:: csharp
  56. using static Godot.GD;
  57. public class Test
  58. {
  59. static Test()
  60. {
  61. Print("Hello"); // Instead of GD.Print("Hello");
  62. }
  63. }
  64. Export keyword
  65. --------------
  66. Use the ``[Export]`` attribute instead of the GDScript ``export`` keyword.
  67. This attribute can also be provided with optional :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>` and ``hintString`` parameters.
  68. Default values can be set by assigning a value.
  69. Example:
  70. .. code-block:: csharp
  71. using Godot;
  72. public partial class MyNode : Node
  73. {
  74. [Export]
  75. private NodePath _nodePath;
  76. [Export]
  77. private string _name = "default";
  78. [Export(PropertyHint.Range, "0,100000,1000,or_greater")]
  79. private int _income;
  80. [Export(PropertyHint.File, "*.png,*.jpg")]
  81. private string _icon;
  82. }
  83. Signal keyword
  84. --------------
  85. Use the ``[Signal]`` attribute to declare a signal instead of the GDScript ``signal`` keyword.
  86. This attribute should be used on a `delegate`, whose name signature will be used to define the signal.
  87. The `delegate` must have the ``EventHandler`` suffix, an `event` will be generated in the class with the same name but without the suffix, use that event's name with ``EmitSignal``.
  88. .. code-block:: csharp
  89. [Signal]
  90. delegate void MySignalEventHandler(string willSendAString);
  91. See also: :ref:`doc_c_sharp_signals`.
  92. `@onready` annotation
  93. ---------------------
  94. GDScript has the ability to defer the initialization of a member variable until the ready function
  95. is called with `@onready` (cf. :ref:`doc_gdscript_onready_annotation`).
  96. For example:
  97. .. code-block:: gdscript
  98. @onready var my_label = get_node("MyLabel")
  99. However C# does not have this ability. To achieve the same effect you need to do this.
  100. .. code-block:: csharp
  101. private Label _myLabel;
  102. public override void _Ready()
  103. {
  104. _myLabel = GetNode<Label>("MyLabel");
  105. }
  106. Singletons
  107. ----------
  108. Singletons are available as static classes rather than using the singleton pattern.
  109. This is to make code less verbose than it would be with an ``Instance`` property.
  110. Example:
  111. .. code-block:: csharp
  112. Input.IsActionPressed("ui_down")
  113. However, in some very rare cases this is not enough. For example, you may want
  114. to access a member from the base class ``Godot.Object``, like ``Connect``.
  115. For such use cases we provide a static property named ``Singleton`` that returns
  116. the singleton instance. The type of this instance is ``Godot.Object``.
  117. Example:
  118. .. code-block:: csharp
  119. Input.Singleton.JoyConnectionChanged += Input_JoyConnectionChanged;
  120. String
  121. ------
  122. Use ``System.String`` (``string``). Most of Godot's String methods have an
  123. equivalent in ``System.String`` or are provided by the ``StringExtensions``
  124. class as extension methods.
  125. Example:
  126. .. code-block:: csharp
  127. string text = "Bigrams";
  128. string[] bigrams = text.Bigrams(); // ["Bi", "ig", "gr", "ra", "am", "ms"]
  129. Strings are immutable in .NET, so all methods that manipulate a string don't
  130. modify the original string and return a newly created string with the
  131. modifications applied. To avoid creating multiple string allocations consider
  132. using a `StringBuilder`_.
  133. List of Godot's String methods and their equivalent in C#:
  134. ======================= ==============================================================
  135. GDScript C#
  136. ======================= ==============================================================
  137. begins_with `string.StartsWith`_
  138. bigrams StringExtensions.Bigrams
  139. bin_to_int StringExtensions.BinToInt
  140. c_escape StringExtensions.CEscape
  141. c_unescape StringExtensions.CUnescape
  142. capitalize StringExtensions.Capitalize
  143. casecmp_to StringExtensions.CasecmpTo or StringExtensions.CompareTo (Consider using `string.Equals`_ or `string.Compare`_)
  144. chr N/A
  145. contains `string.Contains`_
  146. count StringExtensions.Count (Consider using `RegEx`_)
  147. countn StringExtensions.CountN (Consider using `RegEx`_)
  148. dedent StringExtensions.Dedent
  149. ends_with `string.EndsWith`_
  150. find StringExtensions.Find (Consider using `string.IndexOf`_ or `string.IndexOfAny`_)
  151. findn StringExtensions.FindN (Consider using `string.IndexOf`_ or `string.IndexOfAny`_)
  152. format Use `$ string interpolation`_
  153. get_base_dir StringExtensions.GetBaseDir
  154. get_basename StringExtensions.GetBaseName
  155. get_extension StringExtensions.GetExtension
  156. get_file StringExtensions.GetFile
  157. get_slice N/A
  158. get_slice_count N/A
  159. get_slicec N/A
  160. hash StringExtensions.Hash (Consider using `object.GetHashCode`_ unless you need to guarantee the same behavior as in GDScript)
  161. hex_to_int StringExtensions.HexToInt (Consider using `int.Parse`_ or `long.Parse`_ with `System.Globalization.NumberStyles.HexNumber`_)
  162. humanize_size N/A
  163. indent StringExtensions.Indent
  164. insert `string.Insert`_ (Consider using `StringBuilder`_ to manipulate strings)
  165. is_absolute_path StringExtensions.IsAbsolutePath
  166. is_empty `string.IsNullOrEmpty`_ or `string.IsNullOrWhiteSpace`_
  167. is_relative_path StringExtensions.IsRelativePath
  168. is_subsequence_of StringExtensions.IsSubsequenceOf
  169. is_subsequence_ofn StringExtensions.IsSubsequenceOfN
  170. is_valid_filename StringExtensions.IsValidFileName
  171. is_valid_float StringExtensions.IsValidFloat (Consider using `float.TryParse`_ or `double.TryParse`_)
  172. is_valid_hex_number StringExtensions.IsValidHexNumber
  173. is_valid_html_color StringExtensions.IsValidHtmlColor
  174. is_valid_identifier StringExtensions.IsValidIdentifier
  175. is_valid_int StringExtensions.IsValidInt (Consider using `int.TryParse`_ or `long.TryParse`_)
  176. is_valid_ip_address StringExtensions.IsValidIPAddress
  177. join `string.Join`_
  178. json_escape StringExtensions.JSONEscape
  179. left StringExtensions.Left (Consider using `string.Substring`_ or `string.AsSpan`_)
  180. length `string.Length`_
  181. lpad `string.PadLeft`_
  182. lstrip `string.TrimStart`_
  183. match StringExtensions.Match (Consider using `RegEx`_)
  184. matchn StringExtensions.MatchN (Consider using `RegEx`_)
  185. md5_buffer StringExtensions.MD5Buffer (Consider using `System.Security.Cryptography.MD5.HashData`_)
  186. md5_text StringExtensions.MD5Text (Consider using `System.Security.Cryptography.MD5.HashData`_ with StringExtensions.HexEncode)
  187. naturalnocasecmp_to N/A (Consider using `string.Equals`_ or `string.Compare`_)
  188. nocasecmp_to StringExtensions.NocasecmpTo or StringExtensions.CompareTo (Consider using `string.Equals`_ or `string.Compare`_)
  189. num `float.ToString`_ or `double.ToString`_
  190. num_int64 `int.ToString`_ or `long.ToString`_
  191. num_scientific `float.ToString`_ or `double.ToString`_
  192. num_uint64 `uint.ToString`_ or `ulong.ToString`_
  193. pad_decimals StringExtensions.PadDecimals
  194. pad_zeros StringExtensions.PadZeros
  195. path_join StringExtensions.PathJoin
  196. repeat Use `string constructor`_ or a `StringBuilder`_
  197. replace `string.Replace`_ or `RegEx`_
  198. replacen StringExtensions.ReplaceN (Consider using `string.Replace`_ or `RegEx`_)
  199. rfind StringExtensions.RFind (Consider using `string.LastIndexOf`_ or `string.LastIndexOfAny`_)
  200. rfindn StringExtensions.RFindN (Consider using `string.LastIndexOf`_ or `string.LastIndexOfAny`_)
  201. right StringExtensions.Right (Consider using `string.Substring`_ or `string.AsSpan`_)
  202. rpad `string.PadRight`_
  203. rsplit N/A
  204. rstrip `string.TrimEnd`_
  205. sha1_buffer StringExtensions.SHA1Buffer (Consider using `System.Security.Cryptography.SHA1.HashData`_)
  206. sha1_text StringExtensions.SHA1Text (Consider using `System.Security.Cryptography.SHA1.HashData`_ with StringExtensions.HexEncode)
  207. sha256_buffer StringExtensions.SHA256Buffer (Consider using `System.Security.Cryptography.SHA256.HashData`_)
  208. sha256_text StringExtensions.SHA256Text (Consider using `System.Security.Cryptography.SHA256.HashData`_ with StringExtensions.HexEncode)
  209. similarity StringExtensions.Similarity
  210. simplify_path StringExtensions.SimplifyPath
  211. split StringExtensions.Split (Consider using `string.Split`_)
  212. split_floats StringExtensions.SplitFloat
  213. strip_edges StringExtensions.StripEdges (Consider using `string.Trim`_, `string.TrimStart`_ or `string.TrimEnd`_)
  214. strip_escapes StringExtensions.StripEscapes
  215. substr StringExtensions.Substr (Consider using `string.Substring`_ or `string.AsSpan`_)
  216. to_ascii_buffer StringExtensions.ToASCIIBuffer (Consider using `System.Text.Encoding.ASCII.GetBytes`_)
  217. to_camel_case StringExtensions.ToCamelCase
  218. to_float StringExtensions.ToFloat (Consider using `float.TryParse`_ or `double.TryParse`_)
  219. to_int StringExtensions.ToInt (Consider using `int.TryParse`_ or `long.TryParse`_)
  220. to_lower `string.ToLower`_
  221. to_pascal_case StringExtensions.ToPascalCase
  222. to_snake_case StringExtensions.ToSnakeCase
  223. to_upper `string.ToUpper`_
  224. to_utf16_buffer StringExtensions.ToUTF16Buffer (Consider using `System.Text.Encoding.UTF16.GetBytes`_)
  225. to_utf32_buffer StringExtensions.ToUTF32Buffer (Consider using `System.Text.Encoding.UTF32.GetBytes`_)
  226. to_utf8_buffer StringExtensions.ToUTF8Buffer (Consider using `System.Text.Encoding.UTF8.GetBytes`_)
  227. trim_prefix StringExtensions.TrimPrefix
  228. trim_suffix StringExtensions.TrimSuffix
  229. unicode_at `string[int]`_ indexer
  230. uri_decode StringExtensions.URIDecode (Consider using `System.Uri.UnescapeDataString`_)
  231. uri_encode StringExtensions.URIEncode (Consider using `System.Uri.EscapeDataString`_)
  232. validate_node_name StringExtensions.ValidateNodeName
  233. xml_escape StringExtensions.XMLEscape
  234. xml_unescape StringExtensions.XMLUnescape
  235. ======================= ==============================================================
  236. List of Godot's PackedByteArray methods that create a String and their C# equivalent:
  237. ========================= ==============================================================
  238. GDScript C#
  239. ========================= ==============================================================
  240. get_string_from_ascii StringExtensions.GetStringFromASCII (Consider using `System.Text.Encoding.ASCII.GetString`_)
  241. get_string_from_utf16 StringExtensions.GetStringFromUTF16 (Consider using `System.Text.Encoding.UTF16.GetString`_)
  242. get_string_from_utf32 StringExtensions.GetStringFromUTF32 (Consider using `System.Text.Encoding.UTF32.GetString`_)
  243. get_string_from_utf8 StringExtensions.GetStringFromUTF8 (Consider using `System.Text.Encoding.UTF8.GetString`_)
  244. hex_encode StringExtensions.HexEncode (Consider using `System.Convert.ToHexString`_)
  245. ========================= ==============================================================
  246. * .NET contains many path utility methods available under the
  247. `System.IO.Path`_
  248. class that can be used when not dealing with Godot paths (paths that start
  249. with ``res://`` or ``user://``)
  250. .. _$ string interpolation: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated
  251. .. _double.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.double.tostring
  252. .. _double.TryParse: https://learn.microsoft.com/en-us/dotnet/api/system.double.tryparse
  253. .. _float.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.single.tostring
  254. .. _float.TryParse: https://learn.microsoft.com/en-us/dotnet/api/system.single.tryparse
  255. .. _int.Parse: https://learn.microsoft.com/en-us/dotnet/api/system.int32.parse
  256. .. _int.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.int32.tostring
  257. .. _int.TryParse: https://learn.microsoft.com/en-us/dotnet/api/system.int32.tryparse
  258. .. _long.Parse: https://learn.microsoft.com/en-us/dotnet/api/system.int64.parse
  259. .. _long.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tostring
  260. .. _long.TryParse: https://learn.microsoft.com/en-us/dotnet/api/system.int64.tryparse
  261. .. _uint.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.uint32.tostring
  262. .. _ulong.ToString: https://learn.microsoft.com/en-us/dotnet/api/system.uint64.tostring
  263. .. _object.GetHashCode: https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode
  264. .. _RegEx: https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expressions
  265. .. _string constructor: https://learn.microsoft.com/en-us/dotnet/api/system.string.-ctor
  266. .. _string[int]: https://learn.microsoft.com/en-us/dotnet/api/system.string.chars
  267. .. _string.AsSpan: https://learn.microsoft.com/en-us/dotnet/api/system.memoryextensions.asspan
  268. .. _string.Compare: https://learn.microsoft.com/en-us/dotnet/api/system.string.compare
  269. .. _string.Contains: https://learn.microsoft.com/en-us/dotnet/api/system.string.contains
  270. .. _string.EndsWith: https://learn.microsoft.com/en-us/dotnet/api/system.string.endswith
  271. .. _string.Equals: https://learn.microsoft.com/en-us/dotnet/api/system.string.equals
  272. .. _string.IndexOf: https://learn.microsoft.com/en-us/dotnet/api/system.string.indexof
  273. .. _string.IndexOfAny: https://learn.microsoft.com/en-us/dotnet/api/system.string.indexofany
  274. .. _string.Insert: https://learn.microsoft.com/en-us/dotnet/api/system.string.insert
  275. .. _string.IsNullOrEmpty: https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorempty
  276. .. _string.IsNullOrWhiteSpace: https://learn.microsoft.com/en-us/dotnet/api/system.string.isnullorwhitespace
  277. .. _string.Join: https://learn.microsoft.com/en-us/dotnet/api/system.string.join
  278. .. _string.LastIndexOf: https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexof
  279. .. _string.LastIndexOfAny: https://learn.microsoft.com/en-us/dotnet/api/system.string.lastindexofany
  280. .. _string.Length: https://learn.microsoft.com/en-us/dotnet/api/system.string.length
  281. .. _string.PadLeft: https://learn.microsoft.com/en-us/dotnet/api/system.string.padleft
  282. .. _string.PadRight: https://learn.microsoft.com/en-us/dotnet/api/system.string.padright
  283. .. _string.Replace: https://learn.microsoft.com/en-us/dotnet/api/system.string.replace
  284. .. _string.Split: https://learn.microsoft.com/en-us/dotnet/api/system.string.split
  285. .. _string.StartsWith: https://learn.microsoft.com/en-us/dotnet/api/system.string.startswith
  286. .. _string.Substring: https://learn.microsoft.com/en-us/dotnet/api/system.string.substring
  287. .. _string.Trim: https://learn.microsoft.com/en-us/dotnet/api/system.string.trim
  288. .. _string.TrimEnd: https://learn.microsoft.com/en-us/dotnet/api/system.string.trimend
  289. .. _string.TrimStart: https://learn.microsoft.com/en-us/dotnet/api/system.string.trimstart
  290. .. _string.ToLower: https://learn.microsoft.com/en-us/dotnet/api/system.string.tolower
  291. .. _string.ToUpper: https://learn.microsoft.com/en-us/dotnet/api/system.string.toupper
  292. .. _StringBuilder: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder
  293. .. _System.Convert.ToHexString: https://learn.microsoft.com/en-us/dotnet/api/system.convert.tohexstring
  294. .. _System.Globalization.NumberStyles.HexNumber: https://learn.microsoft.com/en-us/dotnet/api/system.globalization.numberstyles#system-globalization-numberstyles-hexnumber
  295. .. _System.IO.Path: https://learn.microsoft.com/en-us/dotnet/api/system.io.path
  296. .. _System.Security.Cryptography.MD5.HashData: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.md5.hashdata
  297. .. _System.Security.Cryptography.SHA1.HashData: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha1.hashdata
  298. .. _System.Security.Cryptography.SHA256.HashData: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.sha256.hashdata
  299. .. _System.Text.Encoding.ASCII.GetBytes: https://learn.microsoft.com/en-us/dotnet/api/system.text.asciiencoding.getbytes
  300. .. _System.Text.Encoding.ASCII.GetString: https://learn.microsoft.com/en-us/dotnet/api/system.text.asciiencoding.getstring
  301. .. _System.Text.Encoding.UTF16.GetBytes: https://learn.microsoft.com/en-us/dotnet/api/system.text.unicodeencoding.getbytes
  302. .. _System.Text.Encoding.UTF16.GetString: https://learn.microsoft.com/en-us/dotnet/api/system.text.unicodeencoding.getstring
  303. .. _System.Text.Encoding.UTF32.GetBytes: https://learn.microsoft.com/en-us/dotnet/api/system.text.utf32encoding.getbytes
  304. .. _System.Text.Encoding.UTF32.GetString: https://learn.microsoft.com/en-us/dotnet/api/system.text.utf32encoding.getstring
  305. .. _System.Text.Encoding.UTF8.GetBytes: https://learn.microsoft.com/en-us/dotnet/api/system.text.utf8encoding.getbytes
  306. .. _System.Text.Encoding.UTF8.GetString: https://learn.microsoft.com/en-us/dotnet/api/system.text.utf8encoding.getstring
  307. .. _System.Uri.EscapeDataString: https://learn.microsoft.com/en-us/dotnet/api/system.uri.escapedatastring
  308. .. _System.Uri.UnescapeDataString: https://learn.microsoft.com/en-us/dotnet/api/system.uri.unescapedatastring
  309. Basis
  310. -----
  311. Structs cannot have parameterless constructors in C#. Therefore, ``new Basis()``
  312. initializes all primitive members to their default value. Use ``Basis.Identity``
  313. for the equivalent of ``Basis()`` in GDScript and C++.
  314. The following method was converted to a property with a different name:
  315. ==================== ==============================================================
  316. GDScript C#
  317. ==================== ==============================================================
  318. ``get_scale()`` ``Scale``
  319. ==================== ==============================================================
  320. Transform2D
  321. -----------
  322. Structs cannot have parameterless constructors in C#. Therefore, ``new Transform2D()``
  323. initializes all primitive members to their default value.
  324. Please use ``Transform2D.Identity`` for the equivalent of ``Transform2D()`` in GDScript and C++.
  325. The following methods were converted to properties with their respective names changed:
  326. ==================== ==============================================================
  327. GDScript C#
  328. ==================== ==============================================================
  329. ``get_rotation()`` ``Rotation``
  330. ``get_scale()`` ``Scale``
  331. ==================== ==============================================================
  332. Plane
  333. -----
  334. The following method was converted to a property with a *slightly* different name:
  335. ================ ==================================================================
  336. GDScript C#
  337. ================ ==================================================================
  338. ``center()`` ``Center``
  339. ================ ==================================================================
  340. Rect2
  341. -----
  342. The following field was converted to a property with a *slightly* different name:
  343. ================ ==================================================================
  344. GDScript C#
  345. ================ ==================================================================
  346. ``end`` ``End``
  347. ================ ==================================================================
  348. The following method was converted to a property with a different name:
  349. ================ ==================================================================
  350. GDScript C#
  351. ================ ==================================================================
  352. ``get_area()`` ``Area``
  353. ================ ==================================================================
  354. Quaternion
  355. ----------
  356. Structs cannot have parameterless constructors in C#. Therefore, ``new Quaternion()``
  357. initializes all primitive members to their default value.
  358. Please use ``Quaternion.Identity`` for the equivalent of ``Quaternion()`` in GDScript and C++.
  359. The following methods were converted to a property with a different name:
  360. ===================== =============================================================
  361. GDScript C#
  362. ===================== =============================================================
  363. ``length()`` ``Length``
  364. ``length_squared()`` ``LengthSquared``
  365. ===================== =============================================================
  366. Array
  367. -----
  368. *This is temporary. PackedArrays will need their own types to be used the way they are meant to.*
  369. ====================== ==============================================================
  370. GDScript C#
  371. ====================== ==============================================================
  372. ``Array`` ``Godot.Collections.Array``
  373. ``PackedInt32Array`` ``int[]``
  374. ``PackedInt64Array`` ``long[]``
  375. ``PackedByteArray`` ``byte[]``
  376. ``PackedFloat32Array`` ``float[]``
  377. ``PackedFloat64Array`` ``double[]``
  378. ``PackedStringArray`` ``String[]``
  379. ``PackedColorArray`` ``Color[]``
  380. ``PackedVector2Array`` ``Vector2[]``
  381. ``PackedVector3Array`` ``Vector3[]``
  382. ====================== ==============================================================
  383. ``Godot.Collections.Array<T>`` is a type-safe wrapper around ``Godot.Collections.Array``.
  384. Use the ``Godot.Collections.Array<T>(Godot.Collections.Array)`` constructor to create one.
  385. Dictionary
  386. ----------
  387. Use ``Godot.Collections.Dictionary``.
  388. ``Godot.Collections.Dictionary<T>`` is a type-safe wrapper around ``Godot.Collections.Dictionary``.
  389. Use the ``Godot.Collections.Dictionary<T>(Godot.Collections.Dictionary)`` constructor to create one.
  390. Variant
  391. -------
  392. ``System.Object`` (``object``) is used instead of ``Variant``.
  393. Communicating with other scripting languages
  394. --------------------------------------------
  395. This is explained extensively in :ref:`doc_cross_language_scripting`.
  396. Yield
  397. -----
  398. Something similar to GDScript's ``yield`` with a single parameter can be achieved with
  399. C#'s `yield keyword <https://docs.microsoft.com/en-US/dotnet/csharp/language-reference/keywords/yield>`_.
  400. The equivalent of yield on signal can be achieved with async/await and ``Godot.Object.ToSignal``.
  401. Example:
  402. .. code-block:: csharp
  403. await ToSignal(timer, "timeout");
  404. GD.Print("After timeout");
  405. Other differences
  406. -----------------
  407. ``preload``, as it works in GDScript, is not available in C#.
  408. Use ``GD.Load`` or ``ResourceLoader.Load`` instead.
  409. Other differences:
  410. ================ ==================================================================
  411. GDScript C#
  412. ================ ==================================================================
  413. ``Color8`` ``Color.Color8``
  414. ``is_inf`` ``float.IsInfinity``
  415. ``is_nan`` ``float.IsNaN``
  416. ``dict2inst`` TODO
  417. ``inst2dict`` TODO
  418. ================ ==================================================================