Getting a total from a user defined variable

Joel joelcnz at gmail.com
Thu Apr 20 19:41:21 UTC 2023


```d
import std;

struct Person {
     string name;
     ulong age;
}

void main() {
     auto p=[Person("Joel", 43), Person("Timothy", 40)];
     writeln("Total: ", p.reduce!((a,b) => a.age+b.age)(0UL)); // 
how do I get the total of ages added together?
}
```


More information about the Digitalmars-d-learn mailing list