How to use Generic Delegate in C#

Action<T>

Encapsulates a method that takes a single parameter and does not return a value.

Action<T1,T2>:

Encapsulates a method that has two parameters and does not return a value.

Action<T1,T2,T3>:

Encapsulates a method that has three and does not return a value.

Action<T1,T2,T3,T4>:

Encapsulates a method that has four and does not return a value.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericDelegate
{
 class Program
 {
     static void Main(string[] args)
     {
         //Action<T>
         Action print = s => Console.WriteLine(s);
         string message = "Hello World";
         print(message);

         //Action<T1,T2>
         Action add = (x, y) => Console.WriteLine(x+y);
         add(1, 2);
       


     }
 }
}

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru