Re: Array vs List<>
Frans Bouma <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.advanced |
|---|---|
| Message-ID | <005201c93ff5$28217af0$786470d0$@nl> |
> > // 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;
> }
> }
> }
That looks like the C# 4.0 zip operator: :)
http://community.bartdesmet.net/blogs/bart/archive/2008/11/03/c-4-0-feature-fo
cus-part-3-intermezzo-linq-s-new-zip-operator.aspx
FB
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives