We can use the length static property of an array to get its length. The length of an array is the total number of elements that an array contains.
array.length
The value returned is an integer that represents the number of elements that the array contains.
// import std.stdioimport std.stdio;// main methodvoid main(string[] args) {// create an arrayint[3] ages;// add valuesages[0] = 18;ages[1] = 34;ages[2] = 50;// print the length of the arraywriteln(ages.length);}
std library.main method.sizeof property on the array. Then, we print the result to the console.