2
foreach ( Effect effect in this.Effects.Where ( e => e.IsTransparentEffect && e.HasGPUSupport ) )
 yield return new RealtimeEffect<TransparentEffect> ( effect );

vs

this.Effects.Where ( e => e.IsTransparentEffect && e.HasGPUSupport )
 .Select ( e => new RealtimeEffect<TransparentEffect> ( e ) );

I somehow think the Select would try to gather the results differently than just yielding it like in #1?

Also would there be any performance difference?

asked Feb 10, 2011 at 0:10

2 Answers 2

2

It's definitely functionally identical (although I've assumed that the lack of a new keyword in your LINQ example was a typo).

There's a bit of null checking in Select, but that's unlikely to significantly affect performance.

Jon Skeet has a good writeup on his blog here: http://msmvps.com/blogs/jon_skeet/archive/2010/12/23/reimplementing-linq-to-objects-part-3-quot-select-quot-and-a-rename.aspx

answered Feb 10, 2011 at 0:16
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks added the new keyword.
1

Both codes will return the same results. Both have deferred execution (i.e. nothing will actually be executed until you start enumerating the result) and stream the results (i.e. not buffered). There shouldn't be a significant performance difference between the two versions

answered Feb 10, 2011 at 0:15

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.