در
به عنوان مثال، از روش WriteAllText() استفاده می کنیم.
فایلی با نام "filename.txt" ایجاد کنید و مقداری محتوا در آن بنویسید. سپس از ReadAllText() استفاده می کنیم.
روش خواندن محتویات فایل:
using System.IO; // include the System.IO namespace
string writeText = "Hello World!"; // Create a text string
File.WriteAllText("filename.txt", writeText); // Create a file and write the content of writeText to it
string readText = File.ReadAllText("filename.txt"); // Read the contents of the file
Console.WriteLine(readText); // Output the content
The output will be:
Hello World!