/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example13_10.cs is used to illustrate the use of the debugger;
this program attempts to access an invalid array element
*/
using System;
public class Example13_10
{
public static void Main()
{
try
{
const int ArraySize = 5;
// create an array
int[] myArray = new int[ArraySize];
// set the elements of the array using a for loop
for (int count = 0; count <= ArraySize; count++)
{
myArray[count] = count;
Console.WriteLine("myArray[" + count + "] = " +
myArray[count]);
}
}
catch (System.IndexOutOfRangeException e)
{
Console.WriteLine("Message = " + e.Message);
Console.WriteLine("StackTrace = " + e.StackTrace);
}
}
}
|