C# Enumerable Min(IEnumerable, Func>)
Description
Invokes a transform function on each element of a sequence and returns the minimum nullable Single value.
Syntax
public static Nullable<float> Min<TSource>(
this IEnumerable<TSource> source,
Func<TSource, Nullable<float>> selector
)
Parameters
TSource
- The type of the elements of source.source
- A sequence of values to determine the minimum value of.selector
- A transform function to apply to each element.
Example
using System;//from ww w . j a va 2s .c o m
using System.Linq;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
Pet[] pets = { new Pet { Name="a", Age=8 },
new Pet { Name="b", Age=4 },
new Pet { Name="c", Age=1 } };
int min = pets.Min(pet => pet.Age);
Console.WriteLine("The youngest animal is age {0}.", min);
}
}
class Pet{
public string Name { get; set; }
public int Age { get; set; }
}
The code above generates the following result.