Sample Delegate Program using C#
Posted by Superadmin on August 14 2022 03:48:45

Sample Delegate Program using C#:

 

 

 

/*
 *  C# Program to Display Results using Delegates
 */
using System;
public class example
{
    public delegate int DelegateHandler(int a, int b);
    public static void Main(string[] args)
    {
        Results Results = new Results();
        DelegateHandler sum = new DelegateHandler(Results.sum);
        int result = sum(50, 20);
        Console.WriteLine("Result is: " + result);
        Console.ReadLine();
    }
}
 
public class Results
{
    public int sum(int a, int b)
    {
        return a + b;
    }
}