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