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

Completely lost help please reviewed video still lost

Challenge Task 1 of 3

In the Program class, declare a public Func field named Square that takes an int and returns an int. Use an anonymous method to assign a delegate that takes an int parameter named number and returns the result of number * number.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    public class Program
    {
        public Action<int, Func<int, int>> DisplayResult = delegate (result, Func<int, int> operation) 
       {
       };


    }
}

3 Answers

Steven Parker
Steven Parker
231,268 Points

It looks like you're working on a completely different challenge here!

Try taking the instructions in small pieces:

  • "declare a public Func field ... " — but you are declaring an Action here.
  • "... named Square ... " — but you're declaring something named "DisplayResult".
  • "... that takes an int and returns an int." — your Action takes an int and returns a Func.
  • "... assign a delegate that takes an int parameter ... " — yours is taking two, one untyped and one Func.
  • "... named number ... " — your two paramerters are named "result" and "operation"
  • "... and returns the result of number * number." — you didn't get to the function body yet

I'm not sure where you got the names and specs you were using, but try again and read the instructions carefully. Break them down into pieces and implement them one piece at a time.

public Func<int, int> Square = delegate (int number) { return number * number; }; public Action<int, Func<int, int>> DisplayResult = delegate (int result, Func<int, int> operation) { int number_square = operation(result); Console.WriteLine(number_square); };

class Program { public static Func<int, int> Square = delegate (int number) { return number * number; }; public static Action<int, Func<int, int>> DisplayResult = delegate (int number, Func<int, int> square) { int number_square = Square(number); Console.WriteLine(string.Format("Square, {0}", number_square)); }; static void Main(string[] args) {
DisplayResult(6, Square); Console.ReadLine(); } }