Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

closed as off-topic by Wayne M, Dan Pichelman, MainMa, Eric Lippert, amon Apr 29 at 22:30

  • This question does not appear to be about software development within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

add comment

1 Answer

up vote 7 down vote accepted

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);
}
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.