C# Arithmetic Operation Of Anonymous Methods

Introduction 

 
C# Anonymous methods provide additional, subtraction, multiplication, and division while parsing the body value. It is available with static and dynamic based value parsing.
 
Additional:
  1. num += a;  
  2.   
  3. Console.WriteLine("Named addition: {0}", num);  
Subtraction:
  1. num -= s;  
  2.   
  3. Console.WriteLine("Named Subtraction: {0}", num);  
Multiplication:
  1. num *= m;  
  2.   
  3. Console.WriteLine("Named Multiplication: {0}", num);  
Division:
  1. num /= d;  
  2.   
  3. Console.WriteLine("Named Division: {0}", num);  
The Delegate Function determines to refer to the method same signature of the delegate. The delegate method calls to the main method that the main method calls for additional, subtraction, multiplication, and division.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6.   
  7. delegate void AnonymousArithmetic(int n);  
  8. namespace Anonymous  
  9. {  
  10.     class TestDelegate  
  11.     {  
  12.         static int num = 20;  
  13.   
  14.         public static void additional(int a)  
  15.         {  
  16.             num += a;  
  17.             Console.WriteLine("Named addition: {0}", num);  
  18.         }  
  19.         public static void subtraction(int s)  
  20.         {  
  21.             num -= s;  
  22.             Console.WriteLine("Named subtraction: {0}", num);  
  23.         }  
  24.         public static void multiplication(int m)  
  25.         {  
  26.             num *= m;  
  27.             Console.WriteLine("Named multiplication: {0}", num);  
  28.         }  
  29.         public static void division(int d)  
  30.         {  
  31.             num /= d;  
  32.             Console.WriteLine("Named division: {0}", num);  
  33.         }  
  34.   
  35.         public static int getNum()  
  36.         {  
  37.             return num;  
  38.         }  
  39.   
  40.         static void Main(string[] args)  
  41.         {  
  42.             //create delegate instances using anonymous method  
  43.             AnonymousArithmetic Anonymousvalue = delegate (int x) {  
  44.                 Console.WriteLine("Anonymous Method: {0}", x);  
  45.             };  
  46.   
  47.             //calling the delegate using the anonymous method   
  48.             Anonymousvalue(20);  
  49.   
  50.             //instantiating the delegate using the additional methods   
  51.             Anonymousvalue = new AnonymousArithmetic(additional);  
  52.             Anonymousvalue(10);  
  53.   
  54.             //instantiating the delegate using the subtraction methods   
  55.             Anonymousvalue = new AnonymousArithmetic(subtraction);  
  56.             Anonymousvalue(10);  
  57.   
  58.             //instantiating the delegate using the multiplication methods   
  59.             Anonymousvalue = new AnonymousArithmetic(multiplication);  
  60.             Anonymousvalue(10);  
  61.   
  62.             //instantiating the delegate using another division methods   
  63.             Anonymousvalue = new AnonymousArithmetic(division);             
  64.             Anonymousvalue(2);  
  65.   
  66.             Console.ReadKey();  
  67.         }  
  68.     }  
  69. }  
Sample Static Output:
 
 
This functionality to be declared is static-based. The same method also can be implemented on Dynamic-based value parsing.