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

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

Click to Watch Video

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]);
        }
    }
}

Algorithm .NET 5 published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue


© 2021 - ErnesTech - Privacy