Traverse list to add elements, C#.

Posted by Addie on Stack Overflow See other posts from Stack Overflow or by Addie
Published on 2010-03-23T19:50:59Z Indexed on 2010/03/23 19:53 UTC
Read the original article Hit count: 415

Filed under:
|
|
|

I have a list of objects. Each object has an integer quantity and a DateTime variable which contains a month and year value. I'd like to traverse the list and pad the list by adding missing months (with quantity 0) so that all consecutive months are represented in the list. What would be the best way to accomplish this?

Example: Original List

{ Jan10, 3 }, { Feb10, 4 }, { Apr10, 2 }, { May10, 2 }, { Aug10, 3 }, { Sep10, -3 }, { Oct10, 6 }, { Nov10, 3 }, { Dec10, 7 }, { Feb11, 3 }

New List

{ Jan10, 3 }, { Feb10, 4 }, {Mar10, 0}, { Apr10, 2 }, { May10, 2 }, { Jun10, 0 }, { Jul10, 0 } { Aug10, 3 }, { Sep10, -3 }, { Oct10, 6 }, { Nov10, 3 }, { Dec10, 7 }, { Jan11, 0 }, { Feb11, 3 }

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ