Find Largest Element from Array Using Lambda Expressions in C#



Declare an array −

int[] arr = { 10, 90, 20, 19, 99, 57 };

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

arr.Max());

Here is the complete code −

Example

 Live Demo

using System;
using System.Linq;
class Demo {
   static void Main() {
      int[] arr = { 10, 90, 20, 19, 99, 57 };
      Console.WriteLine(arr.Max(element => Math.Abs(element)));
   }
}

Output

99
Updated on: 2020-06-22T14:39:54+05:30

567 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements