Quantcast
Channel: User Sinatr - Stack Overflow
Viewing all articles
Browse latest Browse all 350

Min() and Max() or single oldschool foreach?

$
0
0

If I have big collection and I care about performance, should I believe in miracle and use

var min = Y.Min();var max = Y.Max();

or I better be a good engineer and use

var max = double.NegativeInfinity;var min = double.PositiveInfinity;foreach(var y in Y){    if(y > max)        max = y;    if(y < min)        min = y;}

Y is ICollection<double>, because I need Count and foreach. I am curious if type is right, because of min/max and that I will need to iterate collection from end, so there will be

Y.OrderByDescending((o) => o)...

Viewing all articles
Browse latest Browse all 350

Trending Articles