C# Querying With LINQ Functional Programming in C# Lambda Expressions

Christopher Coscina
Christopher Coscina
4,669 Points

My code is correct but I keep receiving an error

My code is correct but I keep receiving this error:

Bummer: Did you use the same variable names in the parameters of the lambda expression?

My code is as follows: public Action<int, Func<int, int>> DisplayResult = (int result, Func<int, int> operation) => { Console.WriteLine(operation(result)); };

Please advise.

Program.cs
using System;

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

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

        static void Main(string[] args)
        {

        }
    }
}

1 Answer

Steven Parker
Steven Parker
155,412 Points

The challenge is expecting you to keep the same parameter names when you refactor. The second parameter was originally named "function" but it has been changed to "operation" in this code.

Also, you don't need to declare parameter types when you write lambda expressions, the type is inferred from the function body.