c# using file.io
using System.IO;
using (StreamReader reader = File.ReadAllText(path))
{
//now your file will be closed correctly,
// without having to call .close()
}
c# using file.io
using System.IO;
using (StreamReader reader = File.ReadAllText(path))
{
//now your file will be closed correctly,
// without having to call .close()
}
c# using file.io
//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();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us