Lambda expression as method parameter

  • Thread starter Thread starter Jon Q Jacobs
  • Start date Start date
J

Jon Q Jacobs

Guest
Every time I think I begin to comprehend the idea of lambda expressions in C# programming, I am proven wrong.

"The Lambda Expression in C# is the shorthand for writing the anonymous function."

In my reading on certain development topics, I run accross numerous examples of lambda expressions passed as parameters to methods. That is almost the ONLY usage of lambda expression in my reading. I tried to write a test example. The result of my test anonymous function is type int, so I tried passing it to a method expecting an int. The error messages told me the method needs to expect a function instead.

I tried the following, which resulted in 7 compile errors:

private void TestLambda(Func<x, y, result> func)
{
string X = result.ToString();
}
...
TestLambda((a, b) => a / b);

How do I code this correctly?

Thanks
Jon Jacobs, There are 10 kinds of people: those who understand binary and those who don't

Continue reading...
 
Back
Top