c# - Foreach way to iterate through years given months? -


var months = 36; 

to iterate through years , have access each year number (according how many months have (above)), i'm doing:

var years = convert.toint32(months / 12);  (int = 1; <= years; i++) {     var year = 12 * i; } 

however, i'm sure there must way of populating new list of integers part of foreach , looping through them (giving me access current element rather recalculating again inside for loop). i'm looking writing foreach. possibly linq .select()? don't current approach.

desired result

foreach(var year in new list<int>(){ 1, 2, 3}) { } 

something this?:

foreach (var year in enumerable.range(1, months / 12)) 

Comments

Popular posts from this blog

sql - Postgresql error: "failed to find conversion function from unknown to text" -

javascript - Why in IE loading image not show at center bottom of page? -

Phantomjs login, redirect and render page after pageLoad finishes -