Easiest way to read from and write to files

后端 未结 12 1850
[愿得一人]
[愿得一人] 2020-11-22 08:04

There are a lot of different ways to read and write files (text files, not binary) in C#.

I just need something that is easy and uses the least amount of c

12条回答
  •  失恋的感觉
    2020-11-22 08:42

    Use File.ReadAllText and File.WriteAllText.

    MSDN example excerpt:

    // Create a file to write to.
    string createText = "Hello and Welcome" + Environment.NewLine;
    File.WriteAllText(path, createText);
    
    ...
    
    // Open the file to read from.
    string readText = File.ReadAllText(path);
    

提交回复
热议问题