I have a simple array, where I store the 5 best times for a game. I then write the array elements to a text file . I get the message that a string reference is not set to an instance of a string
private void Scores()
{
if (!File.Exists("TopTimes1.txt"))
{
File.Create("TopTimes1.txt");
StreamWriter sw = new StreamWriter("TopTimes1.txt");
for (int i = 1; i < 6; i++)
{
[B][I]sw.WriteLine(TimeSpan.Parse(i.ToString()));[/I][/B]
}
sw.Close();
}
else
{
StreamReader sr = new StreamReader("TopTimes1.txt");
for (int i = 0; i < 5; i++)
{
bestTimes[i] = TimeSpan.Parse(sr.ReadLine());
}
sr.Close();
}
}
private void HighestScore()
{
Array.Sort(bestTimes);
if ( timerTime < bestTimes[4])
{
bestTimes[4] = timerTime;
Array.Sort(bestTimes);
StreamWriter sw = new StreamWriter("TopTimes.txt");
for (int i=0; i<5; i++)
{
sw.WriteLine(bestTimes[i]);
}
}
}
I get the message in the bold italics line.