So, IEnumerable uses the IComparable interface to evaluation a call to .Min(). I'm having trouble finding whether or not the nullable types support this. Assuming I have a list of int?, {null, 1, 2}. Will .Min() work?
The following program
using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
List<int?> l = new List<int?>() {1, null, 2};
Console.WriteLine(l.Min());
}
}
outputs 1. If the list is however empty, or contains only null
, the output is null
.
So null
counts as the biggest int
for Min
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With