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 trial

C# Querying With LINQ Functional Programming in C# Actions and Funcs

At 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.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    public class Program
    {
       public Func<int, int> Square = delegate (int number)
       {
           return number * number;
       };


    }
}

Thought 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.

3 Answers

Steven Parker
Steven Parker
231,269 Points

It'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:


:warning:SPOILER ALERT


    public Action<int, Func<int, int>> DisplayResult = delegate (int result, Func<int, int> operation)  
    {
    };

had 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