Skip to content

Instantly share code, notes, and snippets.

@corruptmem
Last active December 11, 2015 03:58
Show Gist options
  • Save corruptmem/4541346 to your computer and use it in GitHub Desktop.
Save corruptmem/4541346 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var lists = new[] { new[] { 1, 2, 3 }.ToList(), new[] { 4, 5, 6 }.ToList() };
var enumerators = lists.Select(x => x.GetEnumerator()).ToList();
var enumeratorEnumerator = enumerators.GetEnumerator();
while(enumeratorEnumerator.MoveNext()) // *******
{
((IEnumerator<int>)enumeratorEnumerator.Current).MoveNext(); // ******
}
var values = enumerators.Select(x => x.Current).ToArray();
Console.WriteLine("{0}, {1}", values[0], values[1]); // Writes 0, 0 (as in, default(int), default(int))
Console.ReadKey();
}
}
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var lists = new[] { new[] { 1, 2, 3 }.ToList(), new[] { 4, 5, 6 }.ToList() };
var enumerators = lists.Select(x => x.GetEnumerator()).ToArray();
for (int i = 0; i < enumerators.Length; i++ ) // *******
{
enumerators[i].MoveNext(); // ******
}
var values = enumerators.Select(x => x.Current).ToArray();
Console.WriteLine("{0}, {1}", values[0], values[1]); // Writes 1, 4
Console.ReadKey();
}
}
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var lists = new[] { new[] { 1, 2, 3 }.ToList(), new[] { 4, 5, 6 }.ToList() };
var enumerators = lists.Select(x => x.GetEnumerator()).ToArray();
foreach (var enumerator in enumerators) // *******
{
enumerator.MoveNext(); // ******
}
var values = enumerators.Select(x => x.Current).ToArray();
Console.WriteLine("{0}, {1}", values[0], values[1]); // Writes 0, 0 (as in, default(int), default(int))
Console.ReadKey();
}
}
using System;
using System.Linq;
class Program
{
static void Main(string[] args)
{
var lists = new[] { new[] { 1, 2, 3 }.ToList(), new[] { 4, 5, 6 }.ToList() };
var enumerators = lists.Select(x => x.GetEnumerator()).ToArray();
foreach (var enumerator in enumerators) // *******
{
enumerator.MoveNext(); // ******
Console.WriteLine(enumerator.Current); // writes 1, then 4
}
var values = enumerators.Select(x => x.Current).ToArray();
Console.WriteLine("{0}, {1}", values[0], values[1]); // Writes 0, 0 (as in, default(int), default(int))
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment