Answers for "max number in array c#"

C#
1

c# array max

----------------------------------------------------
  HIGHEST
----------------------------------------------------
var highest 0;
var index;
var x = 0;
int[] arry = new int[]{1,2,3,4,5,6,7,8};

foreach (dynamic i in arry)
{
  if (i > highest){ highest = i; index = x; }
  x++;
}
----------------------------------------------------
  OR
----------------------------------------------------
using System.Linq;

int maxValue = anArray.Max();
----------------------------------------------------

  
  
  
----------------------------------------------------
  LOWEST
----------------------------------------------------
var highest = 100000000000;
var index;
var x = 0;
int[] arry = new int[]{1,2,3,4,5,6,7,8};

foreach (dynamic i in arry)
{
  if (i < highest){ highest = i; index = x; }
  x++;
}
----------------------------------------------------
Posted by: Guest on February-16-2021
0

finding minimum in c#

int LowestHeight = Math.Min(newPerson.Height, Math.Min(newPerson1.Height, Math.Min(newPerson2.Height, newPerson3.Height)));
Posted by: Guest on September-24-2020

C# Answers by Framework

Browse Popular Code Answers by Language