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
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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