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

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
231,248 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
231,248 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.