Re: Array vs List<>
Ryan Heath <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <[email protected]> |
> // no way to do this without indexed access
> for (int i=0 ; i<a.Length ; i++)
> {
> ProcessElements(a[i], b[i]);
> }
Or you could try to create an IEnumerable combiner.
I have googled a bit at first, but I think I'm using the wrong keywords...
So here's some code [1] of what I mean.
Mind you, I misused KeyValuePair, it is not tested and its coded right
here in my gmail!
HTH
// Ryan
[1]
static IEnumerable<KeyValuePair<T,U>> Combine<T,U>(IEnumerable<T> t,
IEnumerable<U> u)
{
var et = t.GetEnumerator();
var eu = u.GetEnumerator();
while(true)
{
bool tMoved = et.MoveNext();
bool uMoved = eu.MoveNext();
if ( tMoved || uMoved)
{
yield return new KeyValuePair<T,U>(tMoved ? et.Current :
default(T), uMoved ? eu.Current : default(U));
}
if ( !tMoved && !uMoved)
{
break;
}
}
}
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives