I'm using Unity3D, Mono, C# on Mac OSX 10.8. I'm trying to use .Net Enumerable.Zip. But copy-pasting the MSDN example gives me a cs0117 error.
Minimal not working example:
using UnityEngine;
using System.Collections;
using System.Linq;
public class Asteroids : MonoBehaviour {
void Start () {
int[] numbers = { 1, 2, 3, 4 };
string[] words = { "one", "two", "three" };
var numbersAndWords = numbers.Zip(words, (first, second) => first + " " + second);
}
}
Error Message:
error CS1061: Type
int[]' does not contain a definition for
Zip' and no extension methodZip' of type
int[]' could be found (are you missing a using directive or an assembly reference?)
I tried replacing "numbers.Zip" with "Enumerable.Zip", then I got this:
error CS0117:
System.Linq.Enumerable' does not contain a definition for
Zip'
Why did these happend?
Given @SLaks' answer, it's easy to roll your own Zip:
public static IEnumerable<TResult> Zip<TA, TB, TResult>(
this IEnumerable<TA> seqA, IEnumerable<TB> seqB, Func<TA, TB, TResult> func)
{
if (seqA == null) throw new ArgumentNullException("seqA");
if (seqB == null) throw new ArgumentNullException("seqB");
using (var iteratorA = seqA.GetEnumerator())
using (var iteratorB = seqB.GetEnumerator())
{
while (iteratorA.MoveNext() && iteratorB.MoveNext())
{
yield return func(iteratorA.Current, iteratorB.Current);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With