4 ms·
C# 3: (1).UpTo(10).ForEach(x => Console.WriteLine(x)); Of course, "UpTo" requires first extending int, which is trivial: public static class IntExtension
by namelessmike 17y ago
C# 3:
(1).UpTo(10).ForEach(x => Console.WriteLine(x));
Of course, "UpTo" requires first extending int, which is trivial:
public static class IntExtensions {
public static List<int> UpTo(this int start, int end) {
var range = new List<int>();
for(int i = start; i < end; i++) {
range.Add(i);
}
return range;
}
}
- _pius 17y agoThat's cool and all, but I think being able to do this natively in Ruby wins: p *1..10 Edit: you may need to do a "require 'pp'" first.