Skip to content

Commit 23d9944

Browse files
committed
c_sharp_exports.rst: move code comments to text
1 parent 67b1795 commit 23d9944

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
{
@@ -301,9 +312,11 @@ their values are limited to the members of the enum type.
301312
The editor will create a widget in the Inspector, allowing to select none, one,
302313
or multiple of the enum members. The value will be stored as an integer.
303314

315+
A flags enum uses powers of 2 for the values of the enum members. Members that
316+
combine multiple flags using logical OR (``|``) are also possible.
317+
304318
.. code-block:: csharp
305319
306-
// Use power of 2 values for the values of the enum members.
307320
[Flags]
308321
public enum MyEnum
309322
{
@@ -312,20 +325,18 @@ or multiple of the enum members. The value will be stored as an integer.
312325
Earth = 1 << 3,
313326
Wind = 1 << 4,
314327
315-
// A combination of flags is also possible.
316328
FireAndWater = Fire | Water,
317329
}
318330
319331
[Export]
320332
public SpellElements MySpellElements { get; set; }
321333
322334
Integers used as bit flags can store multiple ``true``/``false`` (boolean)
323-
values in one property. By using the ``Flags`` property hint, they
324-
can be set from the editor.
335+
values in one property. By using the ``Flags`` property hint, any of the given
336+
flags can be set from the editor.
325337

326338
.. code-block:: csharp
327339
328-
// Set any of the given flags from the editor.
329340
[Export(PropertyHint.Flags, "Fire,Water,Earth,Wind")]
330341
public int SpellElements { get; set; } = 0;
331342

0 commit comments

Comments
 (0)