Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMatt Thompson
23,413 PointsStep 2. Now, refactor the DisplayResult delegate to use a lambda expression?
I'm not understanding this step.
Current Go:
public Func<int, int> Square => delegate (int number)
{
return number * number;
};
public Action<int, Func<int, int>> DisplayResult => delegate (int result, Func<int, int> function)
{
Console.WriteLine(function(result));
};
8 Answers
Steven Parker
231,275 PointsThe challenge "check work" function seems to be broken.
Not here, but in step one. It should not have passed your refactoring of Square.
A correctly refactored Square would look more like this:
public Func<int, int> Square = number => number * number;
Notice that the equal sign (=) remains, but the term "delegate" does not. Also notice that the "goes to" symbols (=>) are placed between the argument and the returned value. Parentheses are not needed for a single argument, and braces are not needed for a return expression or a single statement.
Try using these guidelines for step 2, and/or review the video.
Also, you might want to report the challenge checker issue as a bug on the Support page.
micram1001
33,833 PointsFor task two, remove all references to variables like ints, Func and the delegate too.
= (result, operation) =>
Aindriu Mac Giolla Eoin
2,056 Points2 minute video on Lambda and then ask this ??
Dávid Polyovka
4,230 PointsThe solution is:
public Action<int, Func<int, int>> DisplayResult = (result, function) =>
{
Console.WriteLine(function(result));
};
Matt Thompson
23,413 PointsGot it thanks!
Gil Wentzel
22,932 PointsI still cannot get the second task. Help please!
Stephanie Hallberg
2,336 PointsFirst task I did
public Func<int, int> Square = (number) =>
and passed.
Second task I tried
public Action<int, Func<int, int>> DisplayResult => (result, Func<int,int> function) =>
.. Nope.. Didn't work. And Considering the incredible short introduction to Lambda I dont think I can solve it.
Another question I have to bypass :/
Jake Steele
6,098 Points<p>public Action<int, Func<int, int>> DisplayResult = (int result, Func<int, int> function) => Console.WriteLine(function(result)); <p>
this should help
Jacob Clark
9,140 Pointspublic Func<int, int> Square = number => number * number;
public Action<int, Func<int, int>> DisplayResult = result, function) => Console.WriteLine(function(result));
Because I have a hell of a time myself with this, here's what worked for me.