Geeks With Blogs
Works on my machine October 2012 Entries
Beware the IEnumerable<T>
If you see IEnumerable<T> as read only collection crippled brother, this post is for you. Many times I found myself loosing couple of hours looking for a bug everywhere, but not in a place where it was. From time to time the bug is caused by my simplified perception of IEnumerable. The thing is, if we do not know the mechanism that serves specific IEnumerable elements, we cannot be sure that each iteration will return equal collections with same objects. It is not a big deal if it hosts immutable ......

Posted On Wednesday, October 31, 2012 12:23 AM

Linq’s ZIP for adjacent items
I found that Linq’s ZIP is really great for adjacent item computations. For example, let’s have a collection of dates: var dates = new DateTime[] { new DateTime(2000,1,1), new DateTime(2000,1,2), new DateTime(2000,1,5) }; How would you compute time difference of adjacent items ? I like to use Zip for this kind of job: dates.Zip(dates.Skip(1), (d1, d2) => d2 - d1); As you might expect, the result will be: { 1 day, 3 days } ......

Posted On Tuesday, October 30, 2012 9:52 PM

Copyright © Jakub Niemyjski | Powered by: GeeksWithBlogs.net | Join free