Answers for "c# int array max"

C#
7

find the max number in an array c#

// Find the max number of this Array using C# build in function
WriteLine("Find the max number of this Array using C# build in function" + Environment.NewLine+ "{ 1,2,3,4,5,6,7,8,9}");
int[] array = new[] { 1,2,3,4,5,6,7,8,9};
var maxNumber = array.Max();
WriteLine($"Max Number Of this Array:{maxNumber}");
Posted by: Guest on August-19-2021
0

find the max number in an array c#

// Find the max number of this array using LINQ
 Console.WriteLine("Find the max number of this Array using C# build in function { 1,2,3,4,5,6,7,8,9}");
 int[] array = new[] { 1,2,3,4,5,6,7,8,9};
 var result= array.Select((n, i) => new { Value = n, Index = i }).FirstOrDefault(s => s.Value == array.Max());
 Console.WriteLine($"Max Number Of this Array:{result?.Value} and index no: {result?.Index}");
Posted by: Guest on August-19-2021

C# Answers by Framework

Browse Popular Code Answers by Language