C# Program To Display Results Using Delegates

This C# program displays the results, using Delegates. Here, Delegate is a type, which holds the method(s) reference in an object. It is also referred to as a type safe function pointer.

Here is the source code of the C# program to display the results, using Delegates. C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

Program 
  1. /* 
  2.  *  C# Program to Display Results using Delegates 
  3.  */  
  4. using System;  
  5. public class example  
  6. {  
  7.     public delegate int DelegateHandler(int a, int b);  
  8.     static void Main(string[] args)  
  9.     {  
  10.         Results Results = new Results();  
  11.         DelegateHandler sum = new DelegateHandler(Results.sum);  
  12.         int result = sum(50, 20);  
  13.         Console.WriteLine("Result is: " + result);  
  14.         Console.ReadLine();  
  15.     }  
  16. }   
Output