s

C# generic delegates edit button Edit

author
Rakesh Kumar Sutar | calendar 25 January 2021 | 1379

Introduction

Before you start with Generic delegates. Please see Delegates. There are three types of Generic Delegates:

  • Func Delegate
  • Action Delegate
  • Predicate Delegate

Example

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{
    class Program
    {

       public static void SampleMethod(string name)
        {
            Console.WriteLine("\n\n\t\t"   "Welcome To "  name);
        }
        public static int Add(int x, int y)
        {
            return x   y;
        }
        public static bool Login(string uid)
        {
            if (uid == "4Beginner")
                return true;
            else
                return false;
             
        }
       
        static public void Main()
        {

            Action action1 = SampleMethod;
            Func func1 = Add;
            Predicate pred1 = Login;
            action1("{4}Beginner");
            Console.WriteLine("\n\n\t\t" func1(5,7));
            Console.WriteLine("\n\n\t\t"   pred1("4Beginner"));
            Console.ReadLine();
        }
    }
}

    



Output