I have an IEnumerable
and an IEnumerable
that I want merged into an IEnumerable
where
I would use something along the lines of -
IEnumerable> Merge(IEnumerable keyCollection, IEnumerable valueCollection)
{
var keys = keyCollection.GetEnumerator();
var values = valueCollection.GetEnumerator();
try
{
keys.Reset();
values.Reset();
while (keys.MoveNext() && values.MoveNext())
{
yield return new KeyValuePair(keys.Current,values.Current);
}
}
finally
{
keys.Dispose();
values.Dispose();
}
}
This should work correctly, and cleanup properly afterwards.