Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Andrew Vasilyev, 2010
- using System;
- namespace rubytrolling
- {
- public static class IntExtension
- {
- public static void Times(this int value, Action action)
- {
- if (action == null) throw new ArgumentNullException("action");
- for (var i = 0; i < value; i++)
- action();
- }
- public static void UpTo(this int value, int to, Action<int> action)
- {
- if (action == null) throw new ArgumentNullException("action");
- for (var i = value; i <= to; i++)
- action(i);
- }
- public static void DownTo(this int value, int to, Action<int> action)
- {
- if (action == null) throw new ArgumentNullException("action");
- for (var i = value; i >= to; i--)
- action(i);
- }
- }
- class Program
- {
- static void Main()
- {
- 10.Times(() => Console.WriteLine("Hello"));
- 5.UpTo(10, Console.WriteLine);
- 10.DownTo(5, Console.WriteLine);
- 1.UpTo(5,
- i => 1.UpTo(5,
- j => Console.WriteLine(i * j)
- )
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement