C# Program to find the smallest element from an array using Lambda Expressions



Declare an array −

int[] arr = { 10, 15, 5, 20};

Now to get the smallest element from an array, use Min() method with lambda expressions −

arr.Min());

Here is the complete code −

Example

 Live Demo

using System; using System.Linq; class Demo {    static void Main() {       int[] arr = { 10, 15, 5, 20};       Console.WriteLine(arr.Min(element => Math.Abs(element)));    } }

Output

5
Updated on: 2020-06-22T14:09:40+05:30

557 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements