VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/func-delegate-in-c-sharp/

⇱ Func Delegate C# - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Func Delegate C#

Last Updated : 26 Sep, 2025

In C#, Func is a built-in generic delegate type that represents a method returning a value. It simplifies working with delegates by removing the need to explicitly declare custom delegate types.

Syntax:

Func<T1, T2, ..., TResult> variableName = method_or_lambda;

  • T1, T2, ... : Input parameter types.
  • TResult: Return type of the method.

Key Points

  • Func is a generic delegate defined in the System namespace.
  • It can take zero to sixteen input parameters.
  • The last type parameter always represents the return type.
  • If a delegate does not return a value, use Action instead.

Example: Custom Delegate (Without Func)


Output
485520

Here, we manually define a delegate type "Delegate" that matches the method signature.

Example 1: Func with One Parameter

Output:

36

Here, Func<int, int> takes one integer parameter and returns an integer result.

Example 2: Func with Two Parameters

Output:

12

This Func<int, int, int> takes two integers and returns their sum.

Example 3: Func with No Parameters

When a method has no input but returns a value

Output:

Hello, World!

Example 4: Func with Statement Block

If logic needs multiple lines, use braces {}.

Output:

20

Using Func with Methods

You can also point a Func delegate to a named method.


Output:

27

Func with LINQ

Func is commonly used in LINQ queries.

Output:

2

4

6

Comment
Article Tags:
Article Tags:

Explore