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

Renuga Devi
Renuga Devi
214 Points

How to declare public Func

How to declare public Func

3 Answers

Steven Parker
Steven Parker
217,573 Points

Just put the word "public" at the beginning of a declaration.

Hi guys, how is Func declared? I find it nowhere in the documentation :'(

Steven Parker
Steven Parker
217,573 Points

Here's a link to the definition of Func in the Microsoft documentation. You can see the instructor looking it up at about 2:45 in the video.

using System;

namespace Treehouse.CodeChallenges { public class Program { //public delegate int Func<in int, out int> Square (int number); //public delegate int Func<in int,out int>(int number); //public delegate string Square(int number);

    public Func<int, int> Square(int number);

    static void Main(string[] args)
    {
        Square = delegate(int number) 
        {
            return number*number;
        }
    }
}

}

Still doesn't work. (none of the ways I tried to declare it)