User Program Communication

Read from File in C#

Used to read from a file.


Syntax
string[] lines = File.ReadLines(fileName);
    

Notes

The File class comes from the System.IO namespace.


Example
using System.IO;

int i = 1;
///will iterate through all names in the file
foreach(string name in File.ReadLines("names.txt")){
    Console.WriteLine("Name " + i + ": " + name);
}

See Also
Documentation

File.ReadLines Method - MSDN

Add to Slack

< User Input   |   Write to File >

© 2019 SyntaxDB. All Rights Reserved.