C#C
C#3y ago
755 replies
Mek

❔ ✅ Pass A Function To Another Function?

// in ErrorHandlers.cs
public void InputInvalid(string error) // pass function with unknown parameter types and unknown number of parameters
{
   if (tries > 0)
   {
      Console.WriteLine("\n" + error + " " + tries + " Tries Left");
      // recall passed function here
    }
    else
    {
       Console.WriteLine("\nNumber Of Attempts Reached. Returning To Welcome Screen.");
       Thread.Sleep(2000);
       Console.Clear();
       Program program = new();
       program.WelcomeScreen();
     }
}
Let's say I have 4 functions. The first function is an error handler that needs to have the parameters of a string and a function. The other 3 functions are functions that execute code and have unknown parameters and parameter types. How would I pass those 3 functions to the error handling function so that the error handling function can call them over again when needed?
Was this page helpful?