【发布时间】:2016-07-02 12:07:25
【问题描述】:
我该怎么做? 我的 hello.txt 字符串是:
string hello = Properties.Resources.hello;
我想要这样:
Random rand = new Random();
IEnumerable<string> lines = File.ReadLines(hello);
var lineToRead = rand.Next(1, lines.Count());
var line = lines.Skip(lineToRead - 1).First();
txtbx_output.Text = line.ToString();
这对我来说没有问题:
IEnumerable<string> lines = File.ReadAllLines(@"my pathblabla\Text\hello.txt");
但不是作为资源!
这让我很生气
【问题讨论】:
-
hello的值是多少? -
我已将 hello.txt 添加为资源。 hello 里面只有两个词,例如:hi 和 hello。然后点击一个按钮后,这些词应该出现......它不起作用我这让我很生气
-
您需要使用 file.ReadLines 吗?
-
资源是编译后的二进制文件,不是文本。
-
File.ReadLines(string path),您需要指定路径,但您指定的是string hello。如果您需要使用File.ReadLines(),那么您需要使用反射找到该资源的路径。