How to get the shortest time and longest time(or timespan) from a list using LINQ?

I would create the list as var listofTimeSpans = new List() then var min = listofTimeSpans.Min(); var max = listofTimeSpans.Max() Regards.

I would create the list as var listofTimeSpans = new List(); then var min = listofTimeSpans.Min(); var max = listofTimeSpans.Max(); Regards.

Thanks for your reply. I was looking at it and there is OrderBy and OrderByDescending functions. Do you know how to order the timespan with total seconds?

Thank you for you reply in advance. – shanthiram Apr 28 '10 at 13:35 You could either use listofTimeSpans.Sort() or var ordered = listofTimeSpans. OrderBy(t=>t); Both have the same results.

I didn't understand what you mean by ordering with total seconds, but you can also use var ordered = listofTimeSpans. OrderBy(t=>t. Seconds); – uvita Apr 28 '10 at 14:01 I am new to LINQ and was thinking wrong.

Max and Min functions worked for me. Thank you again. – shanthiram Apr 28 '10 at 14:27.

I am trying to get the longest and shortest timespan in a list using LINQ. Adding the timespans to listofTimeSpans in a foreach loop. Please help me with this.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions