Link to C# Variant-compatible section directly

This commit is contained in:
31
2024-02-03 19:46:56 -08:00
parent c42e54bfbb
commit 8b94fc9501
9 changed files with 24 additions and 17 deletions

View File

@@ -5,7 +5,8 @@ C# Variant
For a detailed explanation of Variant in general, see the :ref:`Variant <class_Variant>` documentation page.
``Godot.Variant`` is used to represent Godot's native :ref:`Variant <class_Variant>` type. Any Variant-compatible type can be converted from/to it.
``Godot.Variant`` is used to represent Godot's native :ref:`Variant <class_Variant>` type. Any
:ref:`Variant-compatible type <c_sharp_variant_compatible_types>` can be converted from/to it.
We recommend avoiding ``Godot.Variant`` unless it is necessary to interact with untyped engine APIs.
Take advantage of C#'s type safety when possible.
@@ -21,9 +22,14 @@ to a ``Godot.Variant``.
Since the Variant type in C# is a struct, it can't be null. To create a "null"
Variant use the ``default`` keyword or the parameterless constructor.
.. _c_sharp_variant_compatible_types:
Variant-compatible types
------------------------
A Variant-compatible type can be converted to and from a ``Godot.Variant``.
These C# types are Variant-compatible:
* All the `built-in value types <https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/built-in-types-table>`_,
except ``decimal``, ``nint`` and ``nuint``.
* ``string``.