Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2008 > BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
|
BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
This is the forum to discuss the Wrox book Beginning Microsoft Visual C# 2008 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, Eric White; ISBN: 9780470191354
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2011, 11:38 PM
Authorized User
 
Join Date: May 2010
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default returns the highest number in the array explanation needed

I am quite new to C# and programming in general. I am trying to understand the code bellow. thank you in advance.

problem interpreting the above lines

Code:
static int MaxValue(int[] intArray)
        {
            
            int maxVal = intArray[0];
//WHERE DOES IT GET THE VALUE OF intArray.Length
            for (int i = 1; i < intArray.Length; i++) 
                
            {
// WHATS DOES intArray[i] means specially the [i]
                if (intArray[i] > maxVal)
                    maxVal = intArray[i];
               
            }

This the part that calls the second function the firts example on the book was a simple function call: Write();

why on here is like this??
int maxVal = MaxValue(myArray);




This the whole code
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ch06Ex02
{
    class Program
    {
        static int MaxValue(int[] intArray)
        {
            
            int maxVal = intArray[0];
            for (int i = 1; i < intArray.Length; i++)
                
            {
               
                if (intArray[i] > maxVal)
                    maxVal = intArray[i];
               
            }

            
            return maxVal;

        }
        static void Main(string[] args)
        {
            
            int[] myArray = { 1, 8, 3, 6, 2, 5, 9, 3, 0, 2 };
            int maxVal = MaxValue(myArray);
           
            Console.WriteLine("The maximum value in myArray is {0}", maxVal);
            Console.ReadKey();
        }
    }
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
finding the highest number(value) in a data column Yasho Visual Studio 2005 2 September 5th, 2010 01:16 PM
How to make function which returns array? sektor Excel VBA 1 April 11th, 2009 01:05 PM
SUM operator returns a negative number cdias XSLT 7 December 31st, 2004 05:08 PM
Chapter 15 - Explanation needed jeyroz BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 June 3rd, 2004 11:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.