Advertisement
bero_0401

Events

Oct 2nd, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | Source Code | 0 0
  1. using revision;
  2.  
  3. public class Program
  4. {
  5.  
  6.  
  7.     static void Main(String[] args){
  8.  
  9.        
  10.         EventsTest test = new EventsTest();
  11.         test.ExpressionCalculated += Test_ExpressionCalculated;
  12.         test.Calculate(5, 10);
  13.  
  14.     }
  15.  
  16.     private static void Test_ExpressionCalculated(int x, int y)
  17.     {
  18.         Console.WriteLine("Expression Calculted Successfully!");
  19.     }
  20. }
  21.  
  22. public class EventsTest
  23. {
  24.     public event CalculateEventHandler ExpressionCalculated;
  25.     public delegate void CalculateEventHandler(int x, int y);
  26.  
  27.     public int Calculate(int x, int y)
  28.     {
  29.         int result = x + y;
  30.         // trigger - fire - raise.. event
  31.         ExpressionCalculated?.Invoke(x, y);
  32.         Console.WriteLine(result);
  33.         return result;
  34.  
  35.     }
  36.  
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement