
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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
- Related Articles
- Math Operations on BigInteger in Java
- Math operations for BigDecimal in Java
- How to instantiate delegates in C#?
- Bash Math Operations (Bash Arithmetic) Explained
- Delegates in C#
- How to declare and instantiate Delegates in C#?
- What are delegates in C#?
- Events vs Delegates in C#
- What are generic delegates in C#?
- What are multicasting delegates in C#?
- Math Class in C#
- How to perform square root without using math module in Python?
- Difference Between Delegates and Events in C#
- Explain the concept of delegates in C#
- Math class methods in C#

Advertisements