var months = 36;
To iterate through the years and have access to each year number (according to how many months I have (above)), I'm currently doing:
var years = Convert.ToInt32(months / 12);
for (int i = 1; i <= years; i++)
{
var year = 12 * i;
}
However, I'm sure there must be a way of populating a new list of integers as part of a foreach
and looping through them (giving me access to the current element rather than recalculating it again inside the for
loop). I'm looking for help writing that foreach
. Possibly a LINQ .Select()
? I really don't like this current approach.
Desired Result
foreach(var year in new List<int>(){ 1, 2, 3})
{
}