Get minimum and maximum time value from list of object property using Linq

前端 未结 3 590
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 14:54

I have settings object with property

class Settings
{
    DateTime StartTime;
    DateTime EndTime;
}

and I have created a list of this setting

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 15:36

    Assuming you want a minimum and maximum of the time deltas:

    Settings[] settings = ...;
    
    var max = settings.Max(s => s.EndTime - s.StartTime);
    var min = settings.Min(s => s.EndTime - s.StartTime);
    

提交回复
热议问题