TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jamie Dalley
NA
16
5.7k
Why am I getting an IndexOutOfRangeException for this?
Jan 21 2013 8:13 AM
Basically I am doing a C# assignment for part of my uni course. This part of it needs to create an array with 10 items. All the items should be random numbers generated between 0 and 19. The i need to use a for loop to print out what each item is. The problem is i am getting an IndexOutOfRangeException and i have no idea why, so was just wondering if anyone could take a look at it and help me out, tanks in advance, here it is:
int MaxValue;
int RandomNumber;
Random MyRandom;
MaxValue = 20;
MyRandom = new Random();
RandomNumber = MyRandom.Next(MaxValue);
int[] firstArray = new int[9];
for (int i = 0; i < 10; i++)
{
firstArray[i] = RandomNumber;
}
for (int i = 0; i < 10; i++)
{
Console.WriteLine("Item {0} in the array is {1}", i, firstArray[i]);
}
Reply
Answers (
2
)
Visual Studio 2012 Express
Searching from Userform to Database