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

前端 未结 3 585
佛祖请我去吃肉
佛祖请我去吃肉 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:34

    var minStartTime = settings.Min(setting => setting.StartTime);    // returns 8am
    var maxEndTime = settings.Max(setting => setting.EndTime);        // returns 5pm
    

    This returns the lowest and highest times. Other answers are telling you how to get the difference between max and min, which does not appear to be what you asked for.

提交回复
热议问题