Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
217,469 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
217,469 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.