如何写入资源文件?

Bra*_*ble 3 c# file embedded-resource

如果可以从源文件中读取,如下所示:

string fileContent = Resources.Users;

using (var reader = new StringReader(fileContent))
{
    string line;
    while ((line = reader.ReadLine()) != null)
    {
        string[] split = line.Split('|');
        string name = split[0];
        string last = split[1];

    }
}
Run Code Online (Sandbox Code Playgroud)

那你怎么写同一个文件?

Wor*_*und 7

您可以使用ResourceWriter.我还建议您使用ResourceManager从文件中读取.

来自链接源的代码:

using System;
using System.Resources;

public class WriteResources {
   public static void Main(string[] args) {

  // Creates a resource writer.
  IResourceWriter writer = new ResourceWriter("myResources.resources");

  // Adds resources to the resource writer.
  writer.AddResource("String 1", "First String");

  writer.AddResource("String 2", "Second String");

  writer.AddResource("String 3", "Third String");

  // Writes the resources to the file or stream, and closes it.
  writer.Close();
   }
}
Run Code Online (Sandbox Code Playgroud)

  • 包含您链接到的文章的显着内容没有任何问题.事实上,从长远来看,它会使你的答案更好,因为你永远不知道MSDN何时会改变他们的网址 (11认同)