Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2008 > BOOK: Beginning Microsoft Visual C# 2008 ISBN: 978-0-470-19135-4
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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();
        }
    }
}
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:16 PM
How to make function which returns array? sektor Excel VBA 1 April 11th, 2009 02: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 4th, 2004 12:06 AM



All times are GMT -4. The time now is 01:18 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.