title: Pair-wise iteration in C# or sliding window enumerator
body: <p>If I have an IEnumerable like:</p>
  
  <pre><code>string[] items = new string[] { "a", "b", "c", "d" };
  </code></pre>
  
  <p>I would like to loop thru all the pairs of consecutive items (sliding window of size 2). Which would be </p>
  
  <pre><code>("a","b"), ("b", "c"), ("c", "d")
  </code></pre>
  
  <p>My solution was is this </p>
  
  <pre><code>    public static IEnumerable&lt;Pair&lt;T, T&gt;&gt; Pairs(IEnumerable&lt;T&gt; enumerable) {
          IEnumerator&lt;T&gt; e = enumerable.GetEnumerator(); e.MoveNext();
          T current = e.Current;
          while ( e.MoveNext() ) {
              T next = e.Current;
              yield return new Pair&lt;T, T&gt;(current, next);
              current = next;
          }
      }
  
   // used like this :
   foreach (Pair&lt;String,String&gt; pair in IterTools&lt;String&gt;.Pairs(items)) {
      System.Out.PrintLine("{0}, {1}", pair.First, pair.Second)
   }
  </code></pre>
  
  <p>When I wrote this code, I wondered if there are already functions in the .NET framework that do the same thing and do it not just for pairs but for any size tuples. 
  IMHO there should be a nice way to do this kind of sliding window operations.</p>
  
  <p>I use C# 2.0 and I can imagine that with C# 3.0 (w/ LINQ) there are more (and nicer) ways to do this, but I'm primarily interested in C# 2.0 solutions. Though, I will also appreciate C# 3.0 solutions.</p>