this is part of my code ,though the program run(not really correct
)also have this message "Index was outside the bounds of the array"
using (StreamReader sr = new StreamReader("Date.txt"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
Date mydate = new Date();
int monthTemp;
int dayTemp;
int yearTemp;
String[] str = line.Split(' ');
Int32.TryParse(str[0], out monthTemp);
mydate.Month = monthTemp;
Int32.TryParse(str[1], out dayTemp);
mydate.Day = dayTemp;
Int32.TryParse(str[2], out yearTemp);
mydate.Year = yearTemp;
Loading
PrincePosted Feb 3, 2010, 1:41 PM
Mahesh ChandPosted Feb 3, 2010, 10:45 AM
String[] str = line.Split(' ');
This error occurs when you do not enough items in an array. For example, if you have only two items in the array at 0th and 1st position and try to do this:
Int32.TryParse(str[2], out yearTemp);
In the above code you are actually referencing 3rd item of array.
Debug your code and see how many items you have in str.