How do I do the following shown in Javascript in C# 4.0:
var output = doSomething(variable, function() {
// Anonymous function code
});
I'm sure I've seen this somewhere before but I cannot find any examples.
Using a lambda expression (parameterless, therefore empty parentheses), it is very simple:
var output = doSomething(variable, () => {
// Anonymous function code
});
In C# 2.0, the syntax was a bit longer:
SomeType output = doSomething(variable, delegate {
// Anonymous function code
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With