Logo

Programming-Idioms

History of Idiom 165 > diff from v15 to v16

Edit summary for version 16 by abertk:
New D implementation by user [abertk]

Version 15

2017-12-22, 10:47:58

Version 16

2018-02-04, 17:16:56

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Idiom #165 Last element of list

Assign to variable x the last element of list items.

Code
int[42] list;
int x = list[$-1];
Comments bubble
The dollar operator represents the length of the array that's referred to inside the square brackets.
Doc URL
https://dlang.org/spec/arrays.html#array-length