Created
June 30, 2016 12:21
-
-
Save engelmarkus/dd49a023695694b1185b07ceca06b096 to your computer and use it in GitHub Desktop.
C# - adding some rubyness: times extension method for ints
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
namespace Times { | |
static class Extensions { | |
public static void times(this int t, Action f) { | |
for (int i = 0; i < t; ++i) { | |
f(); | |
} | |
} | |
} | |
class Program { | |
static void Greet() { | |
Console.WriteLine("Hi!"); | |
} | |
static void Main() { | |
5.times(Greet); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment