RIP
Tutorial
Tags
Topics
Examples
eBooks
Tutorial by Examples
Declaration and initialization
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[] }
Array operations
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] }
Slices
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
1
Cookie
This website stores cookies on your computer.
We use cookies to enhance your experience on our website and deliver personalized content.
For more details on our cookie usage, please review our
Cookie Policy
and
Privacy Policy
Accept all Cookies
Leave this website