Result is: 70
Users Online
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Latest Articles
Articles Hierarchy
C# Program to Display Results using Delegates
C# Program to Display Results using Delegates
This is a C# Program to display results using delegates.
This C# Program Displays 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 source code of the C# Program to Display Results using Delegates. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Display Results using Delegates */ using System; public class example { public delegate int DelegateHandler(int a, int b); 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; } }
This C# program is used to display results using delegates. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime. Using result variable compute the sum() function by passing 50 and 20 values as an argument.
The sum() function is used to compute the summation of two values, 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. Print the result using delegates.