Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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}");
Comment

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++;
}
----------------------------------------------------
Comment

max index array c#

for ( int i = 0 ; i < ar.Length ; i++ )
			{
				if ( ar [ i ] > ar[imax])
					imax = i;
			}
			return imax;
		
Comment

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}");
Comment

PREVIOUS NEXT
Code Example
Csharp :: Unity gameobject visible to specific camera 
Csharp :: how to concert a list into strinf splitted by coma c# 
Csharp :: null check syntax c# 
Csharp :: c# mongodb get all documents 
Csharp :: asp.net response.redirect new tab 
Csharp :: c# Predicate delegate 
Csharp :: how to get current dir in c# 
Csharp :: trygetvalue dictionary c# example 
Csharp :: c# numbers only 
Csharp :: how to get a length of a string in c# 
Csharp :: maclaurin series 
Csharp :: how to skip bin/Debug/netcoreapp3.1/ on the reltaive path 
Csharp :: c# convert to nullable datetime 
Csharp :: emgucv open image c# 
Csharp :: select random from enum c# 
Csharp :: c# pi 
Csharp :: how to get an arrays length in c# 
Csharp :: unity gameobject find inactive 
Csharp :: c# count directories in directory and subdirectories 
Csharp :: c# check if array contains value 
Csharp :: get domain name from email in asp.net c# 
Csharp :: tostring format 2 decimals 
Csharp :: unity how to create a prefab 
Csharp :: quaternion rotation unity 
Csharp :: delay activity in uipath 
Csharp :: c# substring reverse 
Csharp :: csharp csvhelper 
Csharp :: jagged array to 2d array c# 
Csharp :: sieve 
Csharp :: unity auto scroll 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =