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

Dirk Walzel
Dirk Walzel
5,431 Points

Stuck in Actions and Funcs => Step1 - Did you return number * number? Yeah, I did! ;(

I am stuck at this step, what really bothers me is the make the Func public.

In VS the following code runs

using System; namespace CourseLinq { class Program { static public Func<int, int> Square = delegate (int number) { return number * number; };

    static void Main(string[] args)
    {
    Console.WriteLine(Square(5));
    Console.ReadLine();
    }
}

}

but in TeamTreehouse I get an error, does your anonymous delegate return number*number.

I also tried, which again worked in VS

using System; namespace CourseLinq { class Program { static void Main(string[] args) { Func<int, int> Square = delegate (int number) { return number * number;

        };
  Console.WriteLine(Square(5));
  Console.ReadLine();
    }
}

}

Here I get in TeamTreehouse the message is Func public.

Any ideas?

Thanks a lot in advance

Program.cs
using System;

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

}

}
Dirk Walzel
Dirk Walzel
5,431 Points

Came back and it worked ''' public Func<int, int> Square = delegate (int number) { return number * number; }; '''

1 Answer

Steven Parker
Steven Parker
170,475 Points

:point_right: The field should not be "static".

Also, the challenge syntax checker apparently wants to see spaces around the multiply operator (*).