I want to make this function work in my program, but Visual Studio tells me that MyFunc is a variable but is used like a method, But that’s what I’m trying to do. trying to call it.
static private void TryThisFunc(Delegate MyFunc)
{
try
{
MyFunc(); // MyFunc is a variable but is used like a method
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
You haven’t specified what type of delegate to use. It could be a delegate which takes parameters – in which case clearly you can’t call it with no arguments. You probably want to use a specific delegate type, e.g.