How to get a maximum of more than two numbers in Visual C #?

I have an array of five numbers and an array of two numbers. How can I find out the largest number from these 7 numbers? Is there a way to make things easier?

+3
source share
4 answers
int[] array1 = { 0, 1, 5, 2, 8 };
int[] array2 = { 9, 4 };

int max = array1.Concat(array2).Max();
// max == 9
+28
source

You can try

decimal max = Math.Max(arr1.Max(), arr2.Max());
+10
source

:

Math.Max(Math.Max(a,b), c)//on and on for the number of numbers you have

LINQ:

int[] arr1;
int[] arr2;
int highest = (from number in new List<int>(arr1).AddRange(arr2)
               orderby number descending
               select number).First();
+3

3.5, Linq:

using System.Linq;
var values = new int[] { 1,2,3,4,5 };
var maxValue = values.Max();
+2

Source: https://habr.com/ru/post/1724155/


All Articles