Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
231,268 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
231,268 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)