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

Joshua Graham
Joshua Graham
8,268 Points

Did you return the result of 'number * number' in your anonymous method delegate?

I'm pretty sure it's written to return number*number, what am I missing here?

Program.cs
using System;


namespace Treehouse.CodeChallenges
{
    public class Program
    {

          public Func<int, int> Square = delegate(int number)
          {
            return number*number;
          }
    }
}

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First off, you're doing great! But there's a couple of things going on here. You've forgotten a semicolon which is supposed to be used at the end of the function. And secondly, you need spaces on either side of the *. Remember, that in C# (and other languages) a * is not only a multiplication operator but can also be used as pointers to memory addresses. This is what my function looked like:

 public Func<int, int> Square = delegate(int number)
 {
      return number * number;
 };

Hope this helps!

Joshua Graham
Joshua Graham
8,268 Points

oh...I remember pointers from taking C in college. I guess that would make a difference. thanks