delegates
Wed Oct 29 2025 18:43:38 GMT+0000 (Coordinated Universal Time)
Saved by
@final
using System;
namespace practice
{
public delegate int MathOperation(int x, int y); // Step 1: Declare delegate
public class DelegateExample
{
public static int Add(int x, int y) // Step 2: Define a matching method
{
return x + y;
}
public static void Main()
{
MathOperation d = Add; // Step 3: Assign method to delegate
int res = d(2, 3); // Step 4: Invoke delegate
Console.WriteLine("Result: " + res);
}
}
}
content_copyCOPY
Comments