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
159,129 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