8,497
社区成员
发帖
与我相关
我的任务
分享
list<double> list=new list<double>();
list.add(0.0158);
list.add(0.0238);
list.add(0.0315);
list.add(0.0446);
//stTime表示刚执行的时间...
Math.Round((DateTime.Now - stTime).TotalSeconds / 60, 4);
list.FindLastIndex(d => d<= num);
也就是 取>集合中最小 或者<集合中最大的.
但是处女座最求完美,我这个list可能很多数据(2s add一次 要执行1个月 30*60*24*30=1296000) 130W数据
所以我这个方法虽然有一个点的误差,但是效率是不是要高一些?因为这个操作关系到UI.当然是越快越好..static int TestIndex(double num)
{
List<double> list = new List<double>();
list.Add(0.0158);
list.Add(0.0238);
list.Add(0.0315);
list.Add(0.0446);
return list.Select((d, i) =>
{
return new
{
Value = d,
Index = i
};
}).OrderBy(x => Math.Abs(x.Value - num)).First().Index;
}