back

Returns the last element of the array.

The element is returned by reference, so $(D_PSYMBOL back) can be also used to change the last element of array if it is mutable.

@property ref
inout(T)
back
(
T
)
(
return scope inout(T)[] array
)

Parameters

T

Element type of array.

array inout(T)[]

Built-in array.

Return Value

Type: inout(T)

Last element.

Precondition: array.length > 0.

Examples

string s = "Brecht";
static assert(is(typeof(s.back) == immutable char));
assert(s.back == 't');

wstring w = "Тютчев";
static assert(is(typeof(w.back) == immutable wchar));
assert(w.back == 'в');

dstring d = "Паустовский";
static assert(is(typeof(d.back) == immutable dchar));
assert(d.back == 'й');

Meta