How to check for null while reading from file

Digimstr

Member
Joined
Sep 26, 2014
Messages
7
Programming Experience
Beginner
I apologize the solution I came up with is



//Do While loop to gather each score from text file and load it into an array
do
{
checker = gather.ReadLine();
//Check to see if the end of file has been reached if not process if it has end
if (checker != null)
{
tempgrade = int.Parse(checker);
grade[count] = tempgrade;
Console.WriteLine("The data at element {0:d} is {1:d}.", count, grade[count]);
count++;
}// End if
} while (checker != null && count < MAX); // End Do


I had to move the read above my if loop and move count incremental into if loop

I also had to make sure there was not other readline inside if that way it was not thinking I was reading more than once per iteration.

Once I did this it read element 0 and then all the rest until EoF was reached and then successfully end the do/while.
 
Last edited:
Back
Top Bottom