Links

Categories

Tags


« | Main | »

Closures

By Jewe | January 12, 2015

delegate string Enumerator(int i);

function Enumerator MakeClosure(string greeting)
{
    string[] names = { "Judy", "Christopher", "Helen", "James", "Sandra", "Rick" };
    return function {
        return greeting + names[i];
    };
}

function main()
{
    Enumerator enu = MakeClosure("Hi ");

    println( enu(0) ); // print Hi Judy
    println( enu(5) ); // print Hi Rick
}

Topics: code examples | Comments Off on Closures

Comments are closed.