<(E-Mail Removed)> wrote:
> > Is there an easy way to convert between a List and a Dictionary?
> >
> > My List is already populated through an automatic DataReader->List
> > generator and given to me as a List...
>
>
> This should work pretty well:
>
> Dictionary<int, Order> orders = new Dictionary<int, Order>();
> list.ForEach(delegate(Order o)
> {
> orders.Add(o.orderID, o);
> });
That will certainly work - but I think for situations as simple as
that, I'd usually use the normal foreach loop instead of the ForEach
method taking a delegate. Aside from anything else, introducing
captured variables can make life complicated in a hurry, and the
debugging is more "interesting" with the delegate version.
(In other cases where it brings a benefit, of course, it's a different
matter.)
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too