User Program Communication

Write to File in C#

Used to write to a file.


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

File.WriteAllLines("filename", fileLines);

Notes

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.


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

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

< Read from File   |   Namespace >

© 2018 SyntaxDB. All Rights Reserved.