We know that we can reference to methods by using delegates and can call the methods by calling the instance of delegate.
I want to call a method(which has an optional parameter) by calling instance of delegate.
My code is below
using System;
namespace Testing_Delegates
{
class Program
{
delegate void Order(string abc);
public static void ReverseOrder(string rev = "Optional Param")
{
char[] elements = rev.ToCharArray();
char[] reversed = new char[rev.Length];
for(int i = 0; i < rev.Length; i++)
{
reversed[i] = elements[rev.Length - (i+1)];
}
foreach(char element in reversed)
{
Console.Write(element);
}
}
static void Main(string[] args)
{
Order changeorder = new Order(ReverseOrder);
changeorder();//------Here is error------------
}
}
}
Error is
There is no argument given that corresponds to the required formal parameter 'abc' of 'Program.Order'