Function that receives another function as a parameter in C #

3

In the Lua language you can create a function that receives another function as an argument, for example:

exemplo = function(outrafunction)
  outrafunction()
end

exemplo(function print("alguma coisa") end)

Is there any way to do this using C #?

    
asked by anonymous 07.08.2018 / 06:46

1 answer

2

Your syntax is wrong, but that's fine.

In C # would be:

using System;
using static System.Console;

public class Program {
    public static void Main() => Exemplo(() => WriteLine("alguma coisa"));
    public static void Exemplo(Action outraFunction) => outraFunction();
}

See running on .NET Fiddle . And no Coding Ground . Also put it in GitHub for future reference .

It's essentially a different syntax, but the mechanism is identical.

    
07.08.2018 / 07:03