What is the init property of an array?
Overview
The init property of an array returns an array literal, with each element of the literal being the .init property of the array element.
Syntax
array.init
Return value
It returns an array literal, with each element of the literal initialized.
Example
// import std.stdioimport std.stdio;// main methodvoid main(string[] args) {// create an arraystring[3] names;// add valuesnames[0] = "Theodore";names[1] = "John";names[2] = "Jane";// print the length of the arraywriteln(names.init);}
Explanation
- Line 2: We import the
stdlibrary. - Line 5: We create the main method.
- Lines 9–11: We assign the values to the elements of the array.
- Line 14: We print the
initof the array elements to the console.