class Operation
{
internal Tuple<int, int> FindMinMax(List<int> list)
{
int maximum = int.MinValue, minimum = int.MaxValue;
list.ForEach(n =>
{
minimum = n < minimum ? n : minimum;
maximum = n > maximum ? n : maximum;
});
return Tuple.Create(minimum, maximum);
}
}
使用:
static void Main(string[] args)
{
List<int> numbers = Enumerable.Range(1, 100).OrderBy(x => Guid.NewGuid()).Take(10).ToList();
Operation op = new Operation();
var res = op.FindMinMax(numbers);
var min = res.Item1;
var max = res.Item2;
}