@@ -40,17 +40,17 @@ public static Range<int> MinMax(this IEnumerable<int> source)
4040 // so that the first comparisons in the aggregate function work as expected
4141 var minMax = new Range < int > ( int . MaxValue , int . MinValue , true ) ;
4242
43- long n = 0 ;
43+ bool any = false ;
4444 var result = source . Aggregate < int , Range < int > > ( minMax , ( accumulator , value ) =>
4545 {
4646 var min = Math . Min ( accumulator . Min , value ) ;
4747 var max = Math . Max ( accumulator . Max , value ) ;
48- n ++ ;
48+ any = true ;
4949
5050 return new Range < int > ( min , max ) ;
5151 } ) ;
5252
53- if ( n > 0 )
53+ if ( any )
5454 return result ;
5555
5656 throw new InvalidOperationException ( "source sequence contains no elements" ) ;
@@ -122,17 +122,17 @@ public static Range<long> MinMax(this IEnumerable<long> source)
122122 // so that the first comparisons in the aggregate function work as expected
123123 var minMax = new Range < long > ( long . MaxValue , long . MinValue , true ) ;
124124
125- long n = 0 ;
125+ bool any = false ;
126126 var result = source . Aggregate < long , Range < long > > ( minMax , ( accumulator , value ) =>
127127 {
128128 var min = Math . Min ( accumulator . Min , value ) ;
129129 var max = Math . Max ( accumulator . Max , value ) ;
130- n ++ ;
130+ any = true ;
131131
132132 return new Range < long > ( min , max ) ;
133133 } ) ;
134134
135- if ( n > 0 )
135+ if ( any )
136136 return result ;
137137
138138 throw new InvalidOperationException ( "source sequence contains no elements" ) ;
@@ -204,17 +204,17 @@ public static Range<float> MinMax(this IEnumerable<float> source)
204204 // so that the first comparisons in the aggregate function work as expected
205205 var minMax = new Range < float > ( float . MaxValue , float . MinValue , true ) ;
206206
207- long n = 0 ;
207+ bool any = false ;
208208 var result = source . Aggregate < float , Range < float > > ( minMax , ( accumulator , value ) =>
209209 {
210210 var min = Math . Min ( accumulator . Min , value ) ;
211211 var max = Math . Max ( accumulator . Max , value ) ;
212- n ++ ;
212+ any = true ;
213213
214214 return new Range < float > ( min , max ) ;
215215 } ) ;
216216
217- if ( n > 0 )
217+ if ( any )
218218 return result ;
219219
220220 throw new InvalidOperationException ( "source sequence contains no elements" ) ;
@@ -286,17 +286,17 @@ public static Range<double> MinMax(this IEnumerable<double> source)
286286 // so that the first comparisons in the aggregate function work as expected
287287 var minMax = new Range < double > ( double . MaxValue , double . MinValue , true ) ;
288288
289- long n = 0 ;
289+ bool any = false ;
290290 var result = source . Aggregate < double , Range < double > > ( minMax , ( accumulator , value ) =>
291291 {
292292 var min = Math . Min ( accumulator . Min , value ) ;
293293 var max = Math . Max ( accumulator . Max , value ) ;
294- n ++ ;
294+ any = true ;
295295
296296 return new Range < double > ( min , max ) ;
297297 } ) ;
298298
299- if ( n > 0 )
299+ if ( any )
300300 return result ;
301301
302302 throw new InvalidOperationException ( "source sequence contains no elements" ) ;
@@ -368,17 +368,17 @@ public static Range<decimal> MinMax(this IEnumerable<decimal> source)
368368 // so that the first comparisons in the aggregate function work as expected
369369 var minMax = new Range < decimal > ( decimal . MaxValue , decimal . MinValue , true ) ;
370370
371- long n = 0 ;
371+ bool any = false ;
372372 var result = source . Aggregate < decimal , Range < decimal > > ( minMax , ( accumulator , value ) =>
373373 {
374374 var min = Math . Min ( accumulator . Min , value ) ;
375375 var max = Math . Max ( accumulator . Max , value ) ;
376- n ++ ;
376+ any = true ;
377377
378378 return new Range < decimal > ( min , max ) ;
379379 } ) ;
380380
381- if ( n > 0 )
381+ if ( any )
382382 return result ;
383383
384384 throw new InvalidOperationException ( "source sequence contains no elements" ) ;
0 commit comments