Code · 1 file

Sample D File

D with structs, ranges and templates. Every language sample implements the same small program so you can compare them side by side.

D · 553 B

Sample D file

An idiomatic D example — the same customer program (or, for hardware languages, a small counter design) we offer in every language.

CC0 · free for any use · Verified by an independent tool · Report a problem

sample.d — first linesD
// Sample D program — samplefiles.com
import std.algorithm : map, sum;
import std.stdio : writefln;

struct Customer
{
    int id;
    string name;
    double balance;

    bool isVip() const { return balance >= 10_000; }
}

void main()
{
    auto customers = [
        Customer(1, "Ada", 12_500),
        Customer(2, "Grace", 830.5),
        Customer(3, "Linus", 10_000),
    ];
    foreach (c; customers)
        writefln("%-6s %10.2f %s", c.name, c.balance, c.isVip ? "VIP" : "");
    writefln("Total: %.2f", customers.map!(c => c.balance).sum);
}

File details

Size
553 B (553 bytes)
MIME type
text/x-d
SHA-256
9dbc5040887c9f7583506012c2d6b4f09531ee7eee32c9c03caff6a205d3a888
MD5
5f3cd00047df27a801f65293fd771a73

Download from the command line

curl -L -o sample.d https://files.samplefiles.com/code/d/sample.d

Or check the download in your browser with the checksum calculator.