LINQ Min Function to Get Minimum Value From List
In LINQ, Min() function is useful to get the minimum value from a collection or list. LINQ has made it very easy to find the minimum value from a given data source. Otherwise, in our normal coding, we have to write quite a bit of code to get the minimum value from the list of available values.
Following is the syntax of using linq min() function to find the minimum value from the list of values.
LINQ MIN() Function Syntax C#
int[] Num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int minimumNum = Num.Min();
LINQ MIN() Function Syntax VB.NET
Dim Num As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim minimumNum As Integer = Num.Min()
If you observe the above syntax, we are getting minimum value from "Num" list using linq Min() function.
Now we will see the complete examples of using linq Min() function to get the minimum value from the list in c# and vb.net applications.
LINQ Min() Function Example C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace Linqtutorials
{
class Program
{
static void Main(string[] args)
{
int[] Num = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Console.WriteLine("The Minimum value in the given array is:");
int minimumNum = Num.Min();
Console.WriteLine("The minimum Number is {0}", minimumNum);
Console.ReadLine();
}
}
}
LINQ Min() Function Example VB.NET
Module Module1
Sub Main()
Dim Num As Integer() = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Console.WriteLine("The Minimum value in the given array is:")
Dim minimumNum As Integer = Num.Min()
Console.WriteLine("The minimum Number is {0}", minimumNum)
Console.ReadLine()
End Sub
End Module
If you observe the above examples, we have a integer array “Num” and we are finding the minimum value from the given array using LINQ Min() function.
When we execute the above examples, we will get the result as shown below.
Output of LINQ Min() Function
Following is the result of using the LINQ Min() function to find the lowest / minimum value from the list.
The Minimum Number is 1
0 Comments