Read and write files in C#

Beginner
Developer
Higher Education Educator
K-12 Educator
Student
.NET

Learn how to read from and write to files in C# using the using statement and the File class to keep your code safe and clean.

Learning objectives

After you complete this module, you'll be able to:

  • Open files safely using the using statement and the File class

  • Read data from text files

  • Write and append data to text files

Prerequisites

  • Beginner level experience with basic C# syntax rules

  • Beginner level experience with creating literal values and declaring variables of basic data types like string, int, and decimal

  • Beginner level experience with repeating actions using for, while, and do-while loops

  • Beginner level experience with storing data using arrays and List<T>

  • Beginner level experience with creating methods, parameters, and return values