Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>[edit]: to clarify; this is useful in the generic LINQ / <code>IEnumerable&lt;T&gt;</code> context, where you <strong>can't use</strong> an indexer, because a: it doesn't exist on an enumerable, and b: you can't guarantee that you can read the data more than once. Since the OP mentions lambdas, it occurs that LINQ might not be too far away (and yes, I do realise that LINQ and lambdas are not quite the same thing).</p> <p>It sounds like you need the missing <code>Zip</code> operator; you can spoof it:</p> <pre><code>static void Main() { int[] left = { 1, 2, 3, 4, 5 }; string[] right = { "abc", "def", "ghi", "jkl", "mno" }; // using KeyValuePair&lt;,&gt; approach foreach (var item in left.Zip(right)) { Console.WriteLine("{0}/{1}", item.Key, item.Value); } // using projection approach foreach (string item in left.Zip(right, (x,y) =&gt; string.Format("{0}/{1}", x, y))) { Console.WriteLine(item); } } // library code; written once and stuffed away in a util assembly... // returns each pais as a KeyValuePair&lt;,&gt; static IEnumerable&lt;KeyValuePair&lt;TLeft,TRight&gt;&gt; Zip&lt;TLeft, TRight&gt;( this IEnumerable&lt;TLeft&gt; left, IEnumerable&lt;TRight&gt; right) { return Zip(left, right, (x, y) =&gt; new KeyValuePair&lt;TLeft, TRight&gt;(x, y)); } // accepts a projection from the caller for each pair static IEnumerable&lt;TResult&gt; Zip&lt;TLeft, TRight, TResult&gt;( this IEnumerable&lt;TLeft&gt; left, IEnumerable&lt;TRight&gt; right, Func&lt;TLeft, TRight, TResult&gt; selector) { using(IEnumerator&lt;TLeft&gt; leftE = left.GetEnumerator()) using (IEnumerator&lt;TRight&gt; rightE = right.GetEnumerator()) { while (leftE.MoveNext() &amp;&amp; rightE.MoveNext()) { yield return selector(leftE.Current, rightE.Current); } } } </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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