Advertisement
konalisp

int.To()

Feb 8th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. class Entry {
  6.     static int Main(string[] args) {
  7.         Console.WriteLine("Hello");
  8.         foreach( int index in 1.To(7) ) {
  9.             Console.WriteLine( index );
  10.         }
  11.         return 0;
  12.     }
  13. }
  14.  
  15. static class Extensions {
  16.     public static IEnumerable<int> To(this int from, int to, int step = 1) {
  17.         to++;
  18.         while (!(step > 0 ^ from < to) && from != to) {
  19.             yield return from;
  20.             from += step;
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement