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

Joshua Graham
Joshua Graham
7,948 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
MOD
Jennifer Nordell
Treehouse Moderator

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
7,948 Points

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