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 | 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
Thread Tools Display Modes
  #1 (permalink)  
Old January 6th, 2011, 10: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

static int MaxValue(int[] intArray)
            int maxVal = intArray[0];
            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
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);

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 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 04: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

All times are GMT -4. The time now is 11:49 PM.

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