我有这个列表示例,我想按顺序遍历列表并获取第一周的值低于最小提供值(即 10),并且接下来的 2 周值也低于最小值或至少一个接下来 2 周的值为负数。
例如,“201303”周的值为 8,下周“201304”(-3) 为负数,因此无论“201305”(15) 是否高于最小值,结果都是“201303”。
如果“201304”的值为 3,则不匹配并返回 null。
var weekList = new List<WeekData>() {
new WeekData {PlanningWeek = "201301", Value = 15}, // 31-12-2013
new WeekData {PlanningWeek = "201302", Value = 12}, // 07-01-2013
new WeekData {PlanningWeek = "201303", Value = 8}, // 14-01-2013
new WeekData {PlanningWeek = "201304", Value = -3}, // 21-01-2013
new WeekData {PlanningWeek = "201305", Value = 15}, // 28-01-2013
new WeekData {PlanningWeek = "201306", Value = 12}, // 04-02-2013
new WeekData {PlanningWeek = "201307", Value = 13}, // 11-02-2013
new WeekData {PlanningWeek = "201308", Value = 8}, // 18-02-2013
new WeekData {PlanningWeek = "201309", Value = 15}, // 25-02-2013
new WeekData {PlanningWeek = "201310", Value = 15}, // 04-03-2013
new WeekData {PlanningWeek = "201311", Value = 15} // 11-03-2013
};
public class WeekData
{
public string PlanningWeek { get; set; }
// GetStartDate() being another custom extension method, used later
public DateTime? WeekStartDate { get { return PlanningWeek.GetStartDate(); }}
public long Value { get; set; }
}
这样做的合适集合是什么?排序列表?链表?列表 ?或者是其他东西?
该列表预计最多包含 13 个项目。
如果有人有一个很好的例子来实现这一点,那么这也将非常有帮助。