Open GoogleCodeExporter opened 9 years ago
Compelling feature!
Original comment by Weitzhan...@gmail.com
on 23 Nov 2012 at 8:37
I need this right now !
Original comment by rdingw...@gmail.com
on 5 Dec 2012 at 1:04
You can implement this easily with a combination of using nullables and
Prepend/Concat a null before calling Min/Max, like this:
var some = Enumerable.Range(10, 10);
var none = Enumerable.Range(10, 0);
Console.WriteLine(some.Cast<int?>().Prepend(null).Min()); // prints 10
Console.WriteLine(none.Cast<int?>().Prepend(null).Min()); // prints null
Console.WriteLine(some.Cast<int?>().Prepend(null).Max()); // prints18
Console.WriteLine(none.Cast<int?>().Prepend(null).Max()); // prints null
Once you have a null you can use ?? fault in a value. The implementation in the
blog article[1] suffers from iterating the sequence twice.
[1]
http://blogs.telerik.com/xamlteam/posts/08-10-17/linq-sequence-contains-no-eleme
nts-extension-methods-to-the-rescue.aspx
Original comment by azizatif
on 22 Jun 2013 at 12:15
Original issue reported on code.google.com by
anton.ge...@gmail.com
on 17 Sep 2009 at 8:56