.NET Framework Class Library
EnumerableMinTSource Method (IEnumerableTSource, FuncTSource, Single)

Invokes a transform function on each element of a sequence and returns the minimum Single value.

Namespace:   System.Linq
Assemblies:   System.Linq (in System.Linq.dll)
  System.Core (in System.Core.dll)
<[%$TOPIC/bb549209_en-us_VS_110_2_0_0_0_0%]> _
Public Shared Function Min(Of TSource) ( _
	source As [%$TOPIC/bb549209_en-us_VS_110_2_0_0_0_1%](Of TSource), _
	selector As [%$TOPIC/bb549209_en-us_VS_110_2_0_0_0_2%](Of TSource, [%$TOPIC/bb549209_en-us_VS_110_2_0_0_0_3%]) _
) As [%$TOPIC/bb549209_en-us_VS_110_2_0_0_0_4%]
public static [%$TOPIC/bb549209_en-us_VS_110_2_0_1_0_0%] Min<TSource>(
	this [%$TOPIC/bb549209_en-us_VS_110_2_0_1_0_1%]<TSource> source,
	[%$TOPIC/bb549209_en-us_VS_110_2_0_1_0_2%]<TSource, [%$TOPIC/bb549209_en-us_VS_110_2_0_1_0_3%]> selector
generic<typename TSource>
static [%$TOPIC/bb549209_en-us_VS_110_2_0_2_0_1%] Min(
	[%$TOPIC/bb549209_en-us_VS_110_2_0_2_0_2%]<TSource>^ source, 
	[%$TOPIC/bb549209_en-us_VS_110_2_0_2_0_3%]<TSource, [%$TOPIC/bb549209_en-us_VS_110_2_0_2_0_4%]>^ selector
static member Min : 
        source:[%$TOPIC/bb549209_en-us_VS_110_2_0_3_0_0%]<'TSource> * 
        selector:[%$TOPIC/bb549209_en-us_VS_110_2_0_3_0_1%]<'TSource, [%$TOPIC/bb549209_en-us_VS_110_2_0_3_0_2%]> -> [%$TOPIC/bb549209_en-us_VS_110_2_0_3_0_3%]
JScript does not support generic types or methods.

Type Parameters


The type of the elements of source.


Type: System.Collections.GenericIEnumerableTSource

A sequence of values to determine the minimum value of.

Type: SystemFuncTSource, Single

A transform function to apply to each element.

Return Value

Type: SystemSingle
The minimum value in the sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

source or selector is .


source contains no elements.


The MinTSource(IEnumerableTSource, FuncTSource, Single) method uses the Single implementation of IComparableT to compare values.

You can apply this method to a sequence of arbitrary values if you provide a function, selector, that projects the members of source into a numeric type, specifically Single.

In Visual Basic query expression syntax, an Aggregate Into Min() clause translates to an invocation of Min.


The following code example demonstrates how to use MinTSource(IEnumerableTSource, FuncTSource, Int32) to determine the minimum value in a sequence of projected values.


This code example uses an overload of this overloaded method that is different from the specific overload that this topic describes. To extend the example to this topic, change the body of the selector function.

Structure Pet
        Public Name As String 
        Public Age As Integer 
    End Structure 

    Sub MinEx4()
        ' Create an array of Pet objects. 
        Dim pets() As Pet = {New Pet With {.Name = "Barley", .Age = 8}, _
                             New Pet With {.Name = "Boots", .Age = 4}, _
                             New Pet With {.Name = "Whiskers", .Age = 1}}

        ' Find the youngest pet by passing a  
        ' lambda expression to the Min() method. 
        Dim min As Integer = pets.Min(Function(pet) pet.Age)

        ' Display the result.
        MsgBox("The youngest pet is age " & min)
    End Sub 

    ' This code produces the following output: 
    ' The youngest pet is age 1
class Pet
                public string Name { get; set; }
                public int Age { get; set; }

            public static void MinEx4()
                Pet[] pets = { new Pet { Name="Barley", Age=8 },
                               new Pet { Name="Boots", Age=4 },
                               new Pet { Name="Whiskers", Age=1 } };

                int min = pets.Min(pet => pet.Age);

                Console.WriteLine("The youngest animal is age {0}.", min);

             This code produces the following output:

             The youngest animal is age 1.  
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8