|
@@ -17,14 +17,14 @@
|
|
|
print(array[-3]) # Prints "Second"
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
- var array = new Godot.Collections.Array{"First", 2, 3, "Last"};
|
|
|
+ Godot.Collections.Array array = ["First", 2, 3, "Last"];
|
|
|
GD.Print(array[0]); // Prints "First"
|
|
|
GD.Print(array[2]); // Prints 3
|
|
|
- GD.Print(array[array.Count - 1]); // Prints "Last"
|
|
|
+ GD.Print(array[^1]); // Prints "Last"
|
|
|
|
|
|
- array[2] = "Second";
|
|
|
+ array[1] = "Second";
|
|
|
GD.Print(array[1]); // Prints "Second"
|
|
|
- GD.Print(array[array.Count - 3]); // Prints "Second"
|
|
|
+ GD.Print(array[^3]); // Prints "Second"
|
|
|
[/csharp]
|
|
|
[/codeblocks]
|
|
|
[b]Note:[/b] Arrays are always passed by [b]reference[/b]. To get a copy of an array that can be modified independently of the original array, use [method duplicate].
|
|
@@ -358,7 +358,7 @@
|
|
|
print(array) # Prints [2, 2, 2, 2, 2]
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
- var array = new Godot.Collections.Array();
|
|
|
+ Godot.Collections.Array array = [];
|
|
|
array.Resize(5);
|
|
|
array.Fill(2);
|
|
|
GD.Print(array); // Prints [2, 2, 2, 2, 2]
|
|
@@ -460,7 +460,7 @@
|
|
|
print(["inside", 7].has("7")) # Prints false
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
- var arr = new Godot.Collections.Array { "inside", 7 };
|
|
|
+ Godot.Collections.Array arr = ["inside", 7];
|
|
|
// By C# convention, this method is renamed to `Contains`.
|
|
|
GD.Print(arr.Contains("inside")); // Prints True
|
|
|
GD.Print(arr.Contains("outside")); // Prints False
|
|
@@ -573,7 +573,7 @@
|
|
|
print([1, 2, 3.25, "Hi"].pick_random())
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
- var array = new Godot.Collections.Array { 1, 2, 3.25f, "Hi" };
|
|
|
+ Godot.Collections.Array array = [1, 2, 3.25f, "Hi"];
|
|
|
GD.Print(array.PickRandom()); // May print 1, 2, 3.25, or "Hi".
|
|
|
[/csharp]
|
|
|
[/codeblocks]
|
|
@@ -755,7 +755,7 @@
|
|
|
print(numbers) # Prints [2.5, 5, 8, 10]
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
- var numbers = new Godot.Collections.Array { 10, 5, 2.5, 8 };
|
|
|
+ Godot.Collections.Array numbers = [10, 5, 2.5, 8];
|
|
|
numbers.Sort();
|
|
|
GD.Print(numbers); // Prints [2.5, 5, 8, 10]
|
|
|
[/csharp]
|
|
@@ -817,8 +817,8 @@
|
|
|
[/gdscript]
|
|
|
[csharp]
|
|
|
// Note that concatenation is not possible with C#'s native Array type.
|
|
|
- var array1 = new Godot.Collections.Array{"One", 2};
|
|
|
- var array2 = new Godot.Collections.Array{3, "Four"};
|
|
|
+ Godot.Collections.Array array1 = ["One", 2];
|
|
|
+ Godot.Collections.Array array2 = [3, "Four"];
|
|
|
GD.Print(array1 + array2); // Prints ["One", 2, 3, "Four"]
|
|
|
[/csharp]
|
|
|
[/codeblocks]
|