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

What am I doing wrong here?

I'm getting an error: Did you return the result of 'number * number' in your anonymous method delegate? Restart ?

Program.cs
using System;

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

1 Answer

Steven Parker
Steven Parker
143,175 Points

Apparently, when they say *"returns the result of number * number" they mean it quite literally — the challenge seems to only allow the calculation to be returned directly instead of by creating an intermediate variable.

In actual practice your solution would work exactly the same but it doesn't pass the challenge.

You may want to report this as a bug to the Support staff.