Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Structs

In D, structs are simple aggregations of data and their associated operations on that data:

struct Rectangle
{
    size_t length, width;
    int id;

    size_t area() { return length*width; }
    size_t perimeter() { return 2*(length + width); }
    size_t isSquare() { return length == width; }
    void setId(int id) { this.id = id; }
}