Can somebody explain me lambda expressions & what they can be used for. I have googled for it & have a rough idea. most of the examples give c# code. How about lambda ex
There are actually two things called "lambda expressions", which are rather loosely related:
Lambda expressions are fundamental part of lambda calculus and are closely related to functional programming
In imperative languages, lambda expressions are usually synonyms for anonymous methods. In C#, for example you can pass lambda expression (ie. an expression itself, not just its result) as an argument:
C#:
someCollection.Apply (x => 2*x); // apply expression to every object in collection
// equivalent to
someCollection.Apply (delegate (int x) { return 2 * X; });
Having said that, C does not support anonymous methods. You can, however, use function pointers to achieve similar results:
int multiply (int x)
{
return 2 * x;
}
...
collection_apply (some_collection, multiply);