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 trialDean Wiseman
20,901 PointsAt a loss for what needs to be done here.
Even looking at the documentation on MSDN I can't figure this out. Have no idea how to do what I'm being asked to do here. Re-watching the video doesn't help at all.
using System;
namespace Treehouse.CodeChallenges
{
public class Program
{
public Func<int, int> Square = delegate (int number)
{
return number * number;
};
}
}
3 Answers
Steven Parker
231,269 PointsIt's not too different from what you did in task 1, you just translate the description in the challenge into code. This one just has a few more components to it. I would normally suggest re-watching the video, but you did that already.
You would end up with something like this:
SPOILER ALERT
public Action<int, Func<int, int>> DisplayResult = delegate (int result, Func<int, int> operation)
{
};
Dean Wiseman
20,901 Pointshad the parenthesis in the wrong spot.
public Action<int, Func<int, int>> DisplayResult = delegate(int result, Func<int, int>) operation vs public Action<int, Func<int, int>> DisplayResult = delegate(int result, Func<int, int> operation)
and forgot the curly braces....been a long day.
Thanks for the help Steven
Carel Du Plessis
Courses Plus Student 16,356 Pointsthis is so confusing until you see this documentation https://docs.microsoft.com/en-us/dotnet/api/system.action-2?view=netframework-4.7.2
Dean Wiseman
20,901 PointsDean Wiseman
20,901 PointsThought it would show which challenge it was. Speaking of Challenge Task 2 of 3.
Create a public Action field named DisplayResult that takes an int parameter and a Func<int, int> parameter. Initialize it with an anonymous method delegate that takes an int result parameter, and a Func<int, int> named operation.