Delegates: Print 0..9

unDEFER via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Dec 1 11:28:51 PST 2016


Hello!
Simple using of delegates:

===========
#!/usr/bin/rdmd
import std.stdio;

void main()
{
     void delegate() functions[];

     foreach (i; 0..10)
     {
         void print()
         {
             writefln("%s", i);
         }

         functions ~= &print;
     }

     foreach (i; 0..10)
     {
         functions[i]();
     }
}
=============

Prints
$ ./delegates.d
9
9
9
9
9
9
9
9
9
9

How to print 0..9?


More information about the Digitalmars-d-learn mailing list