T
tshad
I have a set up javascript functions that pass function pointers and I am
trying to figure out how to do the same thing in C# using delegates.
// We define some simple functions here
function add(x,y) {return x + y;}
function subtract(x,y) {return x - 1; }
function multiply(x,y) {return x * 1; }
function divide(x,y) {return x / 1; }
// Here's a function that takes one of the above functions
// as an argument and invokes it on two operands
function operate(operator , operand1, operand2)
{
return operator(operand1, operand2);
}
// We could invoke this function like this to compute the value of (2+3) +
(4*5)
var i = operate (add,operate(add,2,3),operate(multiply,4,5));
Here i = 25;
How would I do the same thing using delegates and is this the best way to do
this?
Thanks,
Tom
trying to figure out how to do the same thing in C# using delegates.
// We define some simple functions here
function add(x,y) {return x + y;}
function subtract(x,y) {return x - 1; }
function multiply(x,y) {return x * 1; }
function divide(x,y) {return x / 1; }
// Here's a function that takes one of the above functions
// as an argument and invokes it on two operands
function operate(operator , operand1, operand2)
{
return operator(operand1, operand2);
}
// We could invoke this function like this to compute the value of (2+3) +
(4*5)
var i = operate (add,operate(add,2,3),operate(multiply,4,5));
Here i = 25;
How would I do the same thing using delegates and is this the best way to do
this?
Thanks,
Tom