Answers for "pass function in as variable C#"

C#
2

pass function in as variable C#

void Function(Func<int> function) //Func<Type> function is the way to define a function
{
  function(); //Fun the function
}
void DoStuff()
{
  Function(function); //Run the function with another function as the input variable
}
int function() //The function to be passed in
{
  Console.WriteLine("Returns 0");
  return 0;
} 
//Func<Type> type cannot be void. The function must return something
Posted by: Guest on February-15-2021

Code answers related to "pass function in as variable C#"

C# Answers by Framework

Browse Popular Code Answers by Language