using System.IO;
using (StreamReader reader = File.ReadAllText(path))
{
//now your file will be closed correctly,
// without having to call .close()
}
//Read the first line of text
string line = sr.ReadLine();
// Correct answers
string [] answerKey = line.Split();
while (true)
{
line = sr.ReadLine();
tokens = line.Split();
id = Convert.ToInt32(tokens[0]);
if (id == 0) break;
string [] studentAnswers = tokens[1].Split();
int score = 0;
// Compare correct answers to student answers
for (int i = 0; i < answerKey.Length; i++) {
if (answerKey[i] == studentAnswers[i]) {
score += 4;
}
else if (studentAnswers[i] != "X") {
score -= 1;
}
}
// Do something with score here.....
}
//close the file
sr.Close();
Console.ReadLine();