Skip to content

Commit 0cb17c0

Browse files
authored
Merge pull request godotengine#8861 from 31/dev/31/export-code-comments
c_sharp_exports.rst: move code comments to text
2 parents b793945 + 23d9944 commit 0cb17c0

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

tutorials/scripting/c_sharp/c_sharp_exports.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,33 @@ Exporting can work with fields and properties.
4848
4949
Exported members can specify a default value; otherwise, the `default value of the type <https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/default-values>`_ is used instead.
5050

51+
An ``int`` like ``_number`` defaults to ``0``. ``_text`` defaults to null
52+
because ``string`` is a reference type.
53+
5154
.. code-block:: csharp
5255
5356
[Export]
54-
private int _number; // Defaults to '0'
57+
private int _number;
5558
5659
[Export]
57-
private string _text; // Defaults to 'null' because it's a reference type
60+
private string _text;
61+
62+
Default values can be specified for fields and properties.
63+
64+
.. code-block:: csharp
5865
5966
[Export]
60-
private string _greeting = "Hello World"; // Exported field specifies a default value
67+
private string _greeting = "Hello World";
6168
6269
[Export]
63-
public string Greeting { get; set; } = "Hello World"; // Exported property specifies a default value
70+
public string Greeting { get; set; } = "Hello World";
71+
72+
Properties with a backing field use the default value of the backing field.
73+
74+
.. code-block:: csharp
75+
76+
private string _greeting = "Hello World";
6477
65-
// This property uses `_greeting` as its backing field, so the default value
66-
// will be the default value of the `_greeting` field.
6778
[Export]
6879
public string GreetingWithBackingField
6980
{
@@ -305,9 +316,11 @@ their values are limited to the members of the enum type.
305316
The editor will create a widget in the Inspector, allowing to select none, one,
306317
or multiple of the enum members. The value will be stored as an integer.
307318

319+
A flags enum uses powers of 2 for the values of the enum members. Members that
320+
combine multiple flags using logical OR (``|``) are also possible.
321+
308322
.. code-block:: csharp
309323
310-
// Use power of 2 values for the values of the enum members.
311324
[Flags]
312325
public enum MyEnum
313326
{
@@ -316,20 +329,18 @@ or multiple of the enum members. The value will be stored as an integer.
316329
Earth = 1 << 3,
317330
Wind = 1 << 4,
318331
319-
// A combination of flags is also possible.
320332
FireAndWater = Fire | Water,
321333
}
322334
323335
[Export]
324336
public SpellElements MySpellElements { get; set; }
325337
326338
Integers used as bit flags can store multiple ``true``/``false`` (boolean)
327-
values in one property. By using the ``Flags`` property hint, they
328-
can be set from the editor.
339+
values in one property. By using the ``Flags`` property hint, any of the given
340+
flags can be set from the editor.
329341

330342
.. code-block:: csharp
331343
332-
// Set any of the given flags from the editor.
333344
[Export(PropertyHint.Flags, "Fire,Water,Earth,Wind")]
334345
public int SpellElements { get; set; } = 0;
335346

0 commit comments

Comments
 (0)