Convert Ruby's times to C#
c#, function, ruby
Solution
You can use the Action type:
public static class Extensions
{
public static void Times(this Int32 times, Action<Int32> action)
{
for (int i = 0; i < times; i++)
action(i);
}
}
class Program
{
delegate void Del();
static void Main(string[] args)
{
5.Times(Console.WriteLine);
// or
5.Times(i => Console.WriteLine(i));
}
}
Also have a look here to learn about delegates.
Problem
I am trying to convert Ruby's time to C#, but I am stuck now. Here's my try: ``` public static class Extensions { public static void Times(this Int32 times, WhatGoesHere?) { for (int i = 0; i < times; i++) ??? } } ``` I am new to C#, and maybe this one should be easy, and I know I want to use Extensionmethods. But since functions are not 'first class ' in C#, I am stuck for now. So, what parametertype should I use for of WhatGoesHere?