Search⌘ K

Properties

Explore the concept of properties in the D programming language, learning how they let you use member functions as if they were variables. Understand how this feature enhances code clarity and functionality, including how slice lengths can be dynamically changed through property assignments without using parentheses.

Introduction

Properties allow using member functions like member variables.

You are familiar with this feature from slices. The length property of a slice returns the number of elements of that slice:

D
import std.stdio;
void main() {
int[] slice = [ 7, 8, 9 ];
writeln(slice.length == 3);
}

Looking merely at that usage, one might think that .length is ...