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

Matthew Ingham
Matthew Ingham
10,068 Points

Actions and Funcs code challenge

With the Actions and Funcs code challenge I am always getting the message "Did you return the result of 'number * number' in your anonymous method delegate?". However I am always returning a result from my anonymous method. Any guidence would be greatly appreciated!

Program.cs
using System;

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

           return square;
       }
    }

}

1 Answer

Steven Parker
Steven Parker
172,328 Points

You'll probably roll your eyes on this one (I did), but apparently when they instructions say "returns the result of number * number" they mean that quite literally. While using an intermediate variable between the calculation and return would certainly work in practice, the challenge doesn't want it done that way here.

Also, you need a semicolon at the end of the delegate definition because it's part of an assignment statement.

Matthew Ingham
Matthew Ingham
10,068 Points

Hi Steven

Many thanks, I guess that is the most efficient way to do it so I can see why they ask for it done that way. Also thanks for pointing out the semi colon, easy to miss. :)

Steven Parker
Steven Parker
172,328 Points

It doesn't seem right for a challenge to fail just for not being "most efficient". You might want to report that as a bug to Support.