T
tshad
In Javascript, you can create an anonymous function (function literal) in
one statement:
c = function(x,y){return x * y}; // define and assign in one line (how
poetic)
alert ("c = " + c(10,20)); // use it here.
But in C# it seems you need to use 2 lines - one being a delegate - to
accomplish the same thing.
delegate int Multiply(int x, int y); // 1st define and give it
a name (so not anonymous, really).
// Also, it
seems to need to be defined outside of a function
// so global.
Multiply c = delegate(int x, int y) { return x * y; }; // 2nd
define - define the function and assign it
Console.WriteLine("c = " + c(10, 20)); // use it here.
Is this correct?
Just trying to get the similarities straight.
Thanks,
Tom
one statement:
c = function(x,y){return x * y}; // define and assign in one line (how
poetic)
alert ("c = " + c(10,20)); // use it here.
But in C# it seems you need to use 2 lines - one being a delegate - to
accomplish the same thing.
delegate int Multiply(int x, int y); // 1st define and give it
a name (so not anonymous, really).
// Also, it
seems to need to be defined outside of a function
// so global.
Multiply c = delegate(int x, int y) { return x * y; }; // 2nd
define - define the function and assign it
Console.WriteLine("c = " + c(10, 20)); // use it here.
Is this correct?
Just trying to get the similarities straight.
Thanks,
Tom