More efficient way to build sum than for loop

后端 未结 4 1739
暗喜
暗喜 2021-01-24 08:07

I have two lists with equal size. Both contain numbers. The first list is generated and the second one is static. Since I have many of the generated lists, I want to find out wh

4条回答
  •  长情又很酷
    2021-01-24 09:04

    I don't think I want to garantee any direct improvment of efficiancy as I can't test it right now but this at least looks nicer:

    if (combination.Count != histDates.Count)
                    return decimal.MaxValue;
    
    return combination.Select((t, i) => Math.Abs(t - histDates[i].Value)).Sum();
    

提交回复
热议问题