Language
Version: 5
Categories
-
User Program Communication
-
Variables
-
Control Flow
-
Object Oriented Programming
-
Strings
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);
}