0

I'll keep it simple, I want to make C#'s methods work like javascript's functions. Mainly so I can convert this -

function makeVariable(terp) {
    var me = {value: 0};
    return function () { terp.stack.push(me); };
}

into C#. Is there ANY way, no matter how complex or time consuming, to do this?

1 Answer 1

7

It is entirely possible although you have to be consistent with your types. The technical term for this is closure.

public Action MakeAction(State s)
{
    var me = new Item();
    return () => s.Stack.Push(me);
}

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.