Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
Multicast Delegates in C#
Next article icon

C# Func Delegate

Last Updated : 01 Feb, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In C#, a delegate is a type that references a method. When creating a custom delegate, we follow these steps:

  1. Declare a delegate with a signature matching the target method.
  2. Create an instance of the delegate.
  3. Invoke the method using the delegate.

But defining custom delegates manually can be repetitive. To simplify this, C# provides a built-in delegate called Func<>, which reduces the need to declare custom delegates explicitly.

Example: Custom Delegate (Without Func)

C#
// C# Program to demonstrate a custom delegate using System;    class Geeks  {       // Custom delegate declaration       public delegate int Delegate(int a, int b, int c, int d);        // Method to be assigned to the delegate       public static int Multiply(int a, int b, int c, int d)       {           return a * b * c * d;       }        static void Main()       {           // Using the custom delegate           Delegate o = Multiply;           Console.WriteLine(o(12, 34, 35, 34));       }   } 

Output
485520 

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

A Func delegate is a built-in generic delegate provided by C#. It simplifies delegate creation by eliminating the need for explicit delegate declarations.

Func Delegate Syntax:

// Func delegate with zero input parameters and one return type

public delegate TResult Func<out TResult>();


// Func delegate with one input parameter and one return type

public delegate TResult Func<in T, out TResult>(T arg);


// Func delegate with two input parameters and one return type

public delegate TResult Func<in T1, in T2, out TResult>(T1 arg1, T2 arg2);


// Func delegate with sixteen input parameters and one return type

public delegate TResult Func<in T1, in T2, …, in T16, out TResult>(

T1 arg1, T2 arg2, …, T16 arg16);

  • T1, T2, … T16: Input parameters
  • TResult: Return type

Example 1: Using Func Delegate

C#
// C# Program to demonstrate Func delegate with a method using System;    class Geeks {       // Method assigned to the Func delegate       public static int Multiply(int a, int b, int c, int d)       {           return a * b * c * d;       }        static void Main()       {           // Using Func delegate (four input parameters, one return type)           Func<int, int, int, int, int> Delegate = Multiply;           Console.WriteLine(Delegate(10, 100, 1000, 1));       }   } 

Output
1000000 

Example 2: Func Delegate with One Parameter

C#
// C# Program to demonstrate  // Func delegate with a single parameter using System;    class Geeks {       // Method assigned to the Func delegate       public static int DoubleValue(int num)       {           return num + num;       }        static void Main()       {           // Func delegate with one input and one return type           Func<int, int> Delegate = DoubleValue;           Console.WriteLine(Delegate(10));       }   } 

Output
20 

Func Delegate with Anonymous Method

Example:

C#
// C# Program to demonstrate Func delegate with an anonymous method using System;  class Geeks {     static void Main()     {         // Using Func delegate with an anonymous method           Func<int, int, int> sum = delegate (int x, int y)          {              return x + y;          };            Console.WriteLine(sum(5, 10));       } } 

Output
15 

Func Delegate with Lambda Expression

Example:

C#
// C# Program to demonstrate  // Func delegate with a lambda expression using System;  class Geeks {     static void Main()     {         // Using Func delegate with a lambda expression           Func<int, int, int> sum = (x, y) => x + y;           Console.WriteLine(sum(5, 10));       } } 

Output
15 

Important Points:

  • Func<> replaces custom delegate declarations, making code more readable.
  • It always returns a value, unlike Action<>, which does not return anything.
  • It supports 0 to 16 input parameters and 1 return parameter.
  • It works well with anonymous methods and lambda expressions.


Next Article
Multicast Delegates in C#
author
ankita_saini
Improve
Article Tags :
  • C#
  • CSharp-Delegates

Similar Reads

  • C# Delegates
    A delegate is an object which refers to a method or you can say it is a reference type variable that can hold a reference to the methods. It provides a way which tells which method is to be called when an event is triggered. For example, if you click on a Button on a form (Windows Form application),
    6 min read
  • C# Predicate Delegate
    A Predicate delegate is an in-built generic type delegate. This delegate is defined under System namespace. It works with those methods which contain some set of criteria and determine whether the passed parameter fulfill the given criteria or not. This delegate takes only one input and returns the
    2 min read
  • Multicast Delegates in C#
    A type-safe function pointer is a delegate. It means that the delegate contains a reference to a method or function, and that when we invoke the delegate, the method to which it refers will be executed. The delegate signature and the method to which it points must both be signed. The method must be
    3 min read
  • C# Action Delegate
    Action delegate in C# is a built-in generic delegate type provided by the .NET framework. It is defined under the System namespace and is used to represent methods that do not return a value i.e. methods with a void return type. The Action delegate can accept from 0 to 16 input parameters of any typ
    3 min read
  • Delegates vs Interfaces in C#
    A Delegate is an object which refers to a method or you can say it is a reference type variable that can hold a reference to the methods. Delegates in C# are similar to the function pointer in C/C++. It provides a way which tells which method is to be called when an event is triggered. Example: C/C+
    3 min read
  • C# Thread Class
    In C#, multi-threading is implemented using the Thread class, which is part of the System.Threading namespace. This class allows for the creation, management, and control of threads within an application. The Thread class provides various methods and properties to handle thread execution, prioritize
    7 min read
  • C# - Handling an Event Declared in an Interface
    Events and event handlers are generally used in case of a Publisher-Subscriber design pattern where some kind of event has occurred in a particular class and it needs to notify other classes about the event. The Publisher class has an event which gets invoked on some condition, the subscribers are n
    4 min read
  • C# Task Class
    The Task class is part of the Task Parallel Library (TPL) in System.Threading.Tasks. Introduced in .NET Framework 4.0, it provides a higher-level abstraction for asynchronous programming and parallelism. It allows operations to run in the background or in parallel with other tasks without blocking t
    10 min read
  • C# | Method Parameters
    Methods in C# are generally the block of codes or statements in a program which gives the user the ability to reuse the same code which ultimately saves the excessive use of memory, acts as a time saver and more importantly, it provides better readability of the code. So you can say a method is a co
    7 min read
  • C# Methods
    A method is a block of code that performs a specific task. It can be executed when called, and it may take inputs, process them, and return a result. Methods can be defined within classes and are used to break down complex programs into simpler, modular pieces. Methods improve code organization, rea
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences