File input and output
Create the small text file shown here next to your program. The program opens it, reads the saved text, and prints it on screen.
Simple example
Read a saved number.
Startinput.txt
Result3
3
using System;
Console.WriteLine(System.IO.File.ReadAllText("input.txt").TrimEnd());
3
Advertisements
Everyday examples
The library leaves the next reservation number in a file. Read the slip number so the next shift can call the right learner.
Startinput.txt
ResultB12
B12
using System;
Console.WriteLine(System.IO.File.ReadAllText("input.txt").TrimEnd());
B12
Run the example
dotnet new console --output Lesson
cp Program.cs Lesson/Program.cs
dotnet run --project Lesson