Ruby vs. C#

02 April 2009

Suppose you wanted to print the numbers from 1 to 10 in C#. No big deal:

  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;
      }
  }
  
  (1).UpTo(10).ForEach(x => Console.WriteLine(x));

So, what does the Ruby look like?

  p *1..10

Ahem.



blog comments powered by Disqus

On Code

On Politics


Get in touch!

pius [at] alum [dot] mit [dot] edu

Twitter listen_to_pius



National Novel Writing Month 2009 Participant