 |
BOOK: Beginning Visual C# 2010
 | This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Visual C# 2010 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
|
|
|
|

November 4th, 2011, 12:10 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
|
|
Chapter 6 Ch06Ex2
Hello,i am trying to learn basic of C# using this book,and i have one question
for example: int maxval=intArray[0],author says that maxval returns the higest number in array.Generally,i want to now what number in brackets means [0]?
What,if for example i put in brackets other number (1,2,4,5...) ?.
Thanks in advance
complete 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();
}
}
}
|
|

November 4th, 2011, 04:49 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The number in square brackets identifies the position in the array.
[0] is position 1
[1] is position 2
[7] is position 8 etc.
Run this to see what I mean.
Cheers
Globox
Code:
static void Main(string[] args)
{
int[] intArray = { 1, 3, 13, 7, 9 };
int maxValue = 0;
for (int i = 0; i < intArray.Length; i++)
{
maxValue = (intArray[i] > maxValue) ? intArray[i] : maxValue;
Console.WriteLine("");
Console.WriteLine("i = " + i.ToString() + " intArray[i] = " + intArray[i]);
}
Console.WriteLine("");
Console.WriteLine("Maximum value in intArray = " + maxValue.ToString());
Console.ReadLine();
}
Quote:
Originally Posted by dampyr
Hello,i am trying to learn basic of C# using this book,and i have one question
for example: int maxval=intArray[0],author says that maxval returns the higest number in array.Generally,i want to now what number in brackets means [0]?
What,if for example i put in brackets other number (1,2,4,5...) ?.
Thanks in advance
complete 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();
}
}
}
|
|
|

November 5th, 2011, 03:17 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
|
|
Solved
I googled the answer:
In the heap, the array is a block of memory made of all the elements together. Each element in the array is identified by a zero-based index number: 0, 1, 2, ... and so on. An attempt to access an index outside the 0..length-1 range will fail with a runtime exception. When first created, all of the elements in the array are set to zero
This is from Java language,but principle is the same:
http://codingbat.com/doc/array.html
|
|

November 5th, 2011, 03:19 PM
|
|
Authorized User
|
|
Join Date: Nov 2011
Posts: 34
Thanks: 14
Thanked 0 Times in 0 Posts
|
|
Lock
Regarding me,a lock can be placed
|
|
 |
|