How to Find Maximum Number in an Array in C#Click to Watch Video

How to find out the Highest Number in an Array in C-Sharp


Question: How do you find out the highest number in the array using C#?

Solution: Before you start coding to find out the highest number of elements in an Array using C#, first think about the different ways to solve the problem

1. One simple way to find out the highest number in an Array or a list is to first sort the list. This way you can know that the last or a first number in the array index is the highest depending on how you have sorted the array.

2. A complex way to solve this problem is by attempting to find the highest number in an Array by not using a built-in Sort() function. This solution/problem can be expected when you are asked to find the Highest Number in the List or Array in a job interview. The main purpose to ask the Interviewee to solve this problem without using a Sort() function is to see how the candidate thinks when approaching the problem.

Below you can find the code in C#:

using System;
using System.Collections.Generic;
using System.Linq;

namespace ErnesTechTutorials
{
    class Program
    {
        static void Main(string[] args)
        {
           Program pg = new Program();
           int[] arraySorting = { 1, 3, 5, 8, -1, 0, 10 };
           pg.findMaximumNumberInArray(arraySorting);
           
        }

        //Find the Maximum number in array
        public void findMaximumNumberInArray(int[] anArrayOfObjects){
         Array.Sort(anArrayOfObjects);
         Console.WriteLine("Found Highest "+ anArrayOfObjects[anArrayOfObjects.Length-1]);
        }
    }
}


.Net 7
published
v.0.01




For peering opportunity Autonomouse System Number: AS401345 Custom Software Development at ErnesTech Email AddressContact: [email protected]