Answers for "c# get file io"

C#
1

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()
}
Posted by: Guest on May-27-2021
0

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();
Posted by: Guest on March-24-2022

C# Answers by Framework

Browse Popular Code Answers by Language