News

 

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 ......

 

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