Tutorial by Examples

import std.stdio; void main() { int[] arr = [1, 2, 3, 4]; writeln(arr.length); // 4 writeln(arr[2]); // 3 // type inference still works auto arr2 = [1, 2, 3, 4]; writeln(typeof(arr2).stringof); // int[] }
import std.stdio; void main() { int[] arr = [1, 2, 3]; // concatenate arr ~= 4; writeln(arr); // [1, 2, 3, 4] // per element operations arr[] += 10 writeln(arr); // [11, 12, 13, 14] }
import std.stdio; void main() { int[] arr = [1, 2, 3, 4, 5]; auto arr2 = arr[1..$ - 1]; // .. is the slice syntax, $ represents the length of the array writeln(arr2); // [2, 3, 4] arr2[0] = 42; writeln(arr[1]); // 42 }

Page 1 of 1