![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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