Skip to content

Instantly share code, notes, and snippets.

@engelmarkus
Created June 30, 2016 12:21
Show Gist options
  • Save engelmarkus/dd49a023695694b1185b07ceca06b096 to your computer and use it in GitHub Desktop.
Save engelmarkus/dd49a023695694b1185b07ceca06b096 to your computer and use it in GitHub Desktop.
C# - adding some rubyness: times extension method for ints
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