Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As was pointed out in another answer, there <em>is</em> a <code>MoveNext()</code> method, and you have access to it for all enumerables via the <code>IEnumerator&lt;T&gt;</code> interface returned by a call to <code>IEnumerable&lt;T&gt;.GetEnumerator()</code>. However, working with <code>MoveNext()</code> and <code>Current</code> can feel somewhat "low-level".</p> <p>If you'd prefer a <code>foreach</code> loop to process your <code>getAlphabet()</code> collection, you could write an extension method that returns elements from any enumerable in pairs of two:</p> <pre><code>public static IEnumerable&lt;T[]&gt; InPairsOfTwo&lt;T&gt;(this IEnumerable&lt;T&gt; enumerable) { if (enumerable.Count() &lt; 2) throw new ArgumentException("..."); T lastItem = default(T); bool isNotFirstIteration = false; foreach (T item in enumerable) { if (isNotFirstIteration) { yield return new T[] { lastItem, item }; } else { isNotFirstIteration = true; } lastItem = item; } } </code></pre> <p>You'd use it as follows:</p> <pre><code>foreach (char[] letterPair in getAlphabet().InPairsOfTwo()) { char currentLetter = letterPair[0], nextLetter = letterPair[1]; Console.WriteLine("# {0}, {1}", currentLetter, nextLetter); } </code></pre> <p>And you'd get the following output:</p> <pre><code># A, B # B, C </code></pre> <p>(Note that while the above extension method returns pairs of two items each, the pairs <em>overlap</em> by one item! You essentially get each item as well as a look-ahead. If you wanted the extension method to return the last item by itself, you could adapt it by adapting the buffering method used.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload