Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to call Math Operations using Delegates in C#?
To understand how to call Math Operations using Delegates in C#, let us see an example wherein we will divide a number.
We have a class and a function in it −
public class Demo {
public static double DivideFunc(double value) {
return value / 5;
}
}
Now, our delegate −
delegate double myDelegate(double x);
Set a value and call −
myDelegate[] val = { Demo.DivideFunc };
result(val[0], 20);
Math operation is called using delegate −
static void result(myDelegate d, double value) {
double result = d(value);
Console.WriteLine("Result = {0}", result);
}
The above displays the following result for “value/ 5” i.e. 20/5 −
Result = 4
Advertisements
