W3School TIY Editor

  • W3School 在线教程
  • 改变方向
  • 暗黑模式
​x
 
using System;
using System.IO;  // 包含 System.IO 命名空间
​
namespace MyApplication
{
  class Program
  {
    static void Main(string[] args)
    {
      string writeText = "Hello World!";  // 创建一个文本字符串
      File.WriteAllText("filename.txt", writeText);  // 创建文件并将 writeText 的内容写入其中
​
      string readText = File.ReadAllText("filename.txt"); // 读取文件内容
      Console.WriteLine(readText); // 输出内容
    }
  }
}