I currently have an object called Week. Week is part of the Season object. the season may contain many weeks. What I want to do is find the position of my week (this is the first week of the season (like # 1), or this is the second (like # 2).
int i = 0;
foreach ( var w in Season.Weeks.OrderBy(w => w.WeekStarts)){
if(w.Id == Id){
return i;
}
i+=1;
}
At the moment, this is what I have. I order weeks in a second to start them, to make sure they are in the correct order. and I scroll through them until I find a week that matches the week in which I am watching. and return the int I am counting.
I feel that there should be an easier linq way to do this, as it feels pretty dirty!
Steve source
share