User Program Communication

Write to File in C#

Used to write to a file.

///declare an array of strings first, each array element being a file line
string[] fileLines = { }; ///lines in here

File.WriteAllLines("filename", fileLines);


The File class is within the System.IO namespace.

A StreamWriter can be used to write one line at a time and call the WriteLine() method.

string[] grades = {"Student 1: 85", "Student 2: 60", "Student 3: 75"};

File.WriteAllLines("grades.txt", grades);

< Read from File   |   Namespace >

© 2019 SyntaxDB. All Rights Reserved.