The following program demonstrates an Example of Action and Func Delegates in C#.

Basically, Action is a delegate that represents a function that doesn’t return a value. In contrast, the Func delegate represents a method that returns a value. Both of these delegates take one or more arguments.

The following program shows the use of Action delegate in computing the multiplication of two numbers. While the second Action delegate computes an expression. Similarly, the first Func delegate returns the sum of two numbers. Whereas the second Func delegate returns the value of an expression.

using System;
namespace ActionAndFuncDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Action<int, int> ob1 = (x, y) => Console.WriteLine(x * y);
            ob1(12, 15);
            Action<int, int> ob11 = (a, b) => Console.WriteLine(Math.Sqrt(a * a + b * b));
            ob11(3, 4);

            Func<int, int, int> ob2 = (x, y) => x + y;
            int z = ob2(12, 15);
            Console.WriteLine("Sum = {0}", z);
            Func<int, int, double> ob21 = (a, b) => Math.Sqrt(a * a + b * b);
            Console.WriteLine($"Result = {ob21(3, 4)}");
        }
    }
}

Output

Demonstrating an Example of Action and Func Delegates in C#
Demonstrating an Example of Action and Func Delegates in C#

Further Reading

Selection Sort in C#

Insertion Sort in C#

Bubble Sort in C#

How to Create Instance Variables and Class Variables in Python

Comparing Rows of Two Tables with ADO.NET

Example of Label and Textbox Control in ASP.NET

One Dimensional and Two Dimensuonal Indexers in C#

Private and Static Constructors in C#

Princites

IITM Software Development Cell