Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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()
}
Comment

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();

Comment

PREVIOUS NEXT
Code Example
Csharp :: list all files in directory and subdirectories c# 
Csharp :: xamarin hide back button 
Csharp :: if button is pressed unity 
Csharp :: c# unity detect any keyboard input but not mouse input 
Csharp :: how to make panel scrollable c# 
Csharp :: c# ftp file download 
Csharp :: how to set rigidbody velocity in unity 
Csharp :: unit test throw exception c# xunit 
Csharp :: linq query select top 1 c# 
Csharp :: serilog minimum log level 
Csharp :: c# merging two arrays 
Csharp :: get client ip address c# 
Csharp :: c# datagridview selected row index 
Csharp :: unity pick random number 
Csharp :: c# datetime format ymd 
Csharp :: capitalize first letter c# 
Csharp :: how to see image from website in wpf 
Csharp :: unity vs unreal for beginners 
Csharp :: unity random string 
Csharp :: how to import datagridview to datatable in c# 
Csharp :: winforms C# code cross thread operation is not valid 
Csharp :: c# add to array 
Csharp :: particle system start color 
Csharp :: validating file upload asp.net core mvc 
Csharp :: string to camel case c# 
Csharp :: change color of object unity 
Csharp :: unity create empty gameobject in code 
Csharp :: c# settings file 
Csharp :: c# function return 
Csharp :: how to get total scenes unity 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =