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

前端 未结 3 593
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  旧时难觅i
    2021-01-22 15:27

    Do it like this

    var max = (from item in myList
          select item.StartTime - item.EndTime).Max()
    
    var min = (from item in myList
          select item.StartTime - item.EndTime).Min()
    

提交回复
热议问题