我已经写了一个函数来通过搜索文本来找到该行,并且在找到特定的行后,我想读取下一行并返回该文本。功能如下:不是所有的代码路径都返回一个值
public static string NextString(string textfind)
{
List<string> found = new List<string>();
string linejd;
using (StreamReader efile = new StreamReader(FILENAME))
{
int counter = 0;
while ((linejd = efile.ReadLine()) != null)
{
counter++;
if (linejd.Contains(textfind))
{
found.Add(linejd);
string nextstring = efile.ReadLine();
return nextstring;
}
}
}
}
文件名已被定义为:
const string FILENAME = @"E:\model\Yen and Lee\AQRun01\eratc.inp";
不过,我不断收到错误:
AQ.Program.NextString(string)': not all code paths return a value
放'返回nextstring;''外使用(声明){}'。 – 2014-10-06 23:12:13
该方法在不进入while循环时应该返回什么? – abatishchev 2014-10-06 23:20:43