Wednesday, May 16, 2012

How to find the highest number in an array using .net


int[] isNum = { 1, 4, 6, 10, 9, 12, 3, 5 };
            int iMaxvalue=0;          
            for (int i = 0; i < isNum.Length; i++)
            {               
                if(iMaxvalue<Convert.ToInt32(isNum[i].ToString()))
                {
                    iMaxvalue = Convert.ToInt32(isNum[i].ToString());
                }
            }

(or)

int itestValue = isNum.Max();

No comments:

Post a Comment

Comments

Protected by Copyscape Plagiarism Software