In LINQ, the Max() function is useful to return the maximum value from the collection. LINQ has made it easy to find the maximum value from a given data source using Max() function. Otherwise, in our standard coding, we have to write quite a bit of code to get maximum value from the list of values.
Following is the syntax of using the LINQ Max() function to get the maximum value from the list or collection in c# and vb.net.
If you observe the above syntax, we get the maximum value from the "Num" list using the LINQ Max() function.
The following are the examples of using the LINQ Max() function to get the maximum number from the list of array values in c# and vb.net.
if you observe the above examples, we have a integer array “Num” and we are trying to find the maximum value from a given array using LINQ Max() function.
When we execute the above examples, we will get the following result.
Following is the result of using the LINQ Max() function to find the highest / maximum value from the list in c# and vb.net.
This is how we can use LINQ Max() function to get max / maximum value from the list or collection.