public class QuoteGenerator
{
public static randomQuote()
{
string t = "Quotes.txt";
List<string> Quotes = new List<string>();
using (StreamReader quoteReader = new StreamReader(t))
{
string line = "";
while ((line = quoteReader.ReadLine()) != null)
{
Quotes.Add(line);
}
}
string[] response = Quotes.ToArray();
string[] shuffle = Classes.RandomStringArrayTool.RandomizeStrings(response);
return (shuffle[0]);
}
}
这里就是我们的工作返回给用户,我想我上面的StreamReader的代码将工作一样:,我需要一个线串的从文本文件在C#
public string randomQuote()
{
string[] response = new string[] {"The fortune you seek, is in another bot"
, "Someone has Googled you recently"
, "This fortune no good. Try another"
, "404 fortune not found"};
string[] shuffle = Classes.RandomStringArrayTool.RandomizeStrings(response);
return shuffle[0];
}
我需要要从StreamReader方法返回引用的第一行,我怎么把代码放在一起似乎不起作用?我想过对引号进行硬编码,但也许将它们保存在文本文件中是个好主意。我想我不明白如何使用StreamReader的工作。任何人都可以请解释一下,自7月份以来我一直在编码。谢谢!
http://stackoverflow.com/questions/1262965/how-do-i-read-a-specified-line-in-a-text-file – Illedan
_ “我怎么把我放在一起的代码看起来不起作用?” - 不起作用**如何**?具体是什么是你遇到的问题?错误讯息?输出错误?异常抛出?解决你的问题,以便包含一个好的[mcve],并且清楚详细地解释到底是什么问题,以及到目前为止所做的努力来解决问题。确保包含任何错误或异常消息的_exact_文本,并为异常完成堆栈跟踪。 –
对不起,由于缺乏我的问题中的细节,我刚开始编写代码,对于我来说有些困难。没有错误消息和代码编译,只是没有输出。雷·威尔逊能够指出我需要仔细检查。 – kcd