我正在写一份关于求职面试的课程.一切都正常,除了一件事.当我使用外部方法TotalLines(我有单独的StreamReader)时,它工作正常,但是当我在程序中计算一些totalLines时,我在第一个问题的开头就收到一个问号.所以它是这样的:
?你叫什么名字?
但是在我正在阅读的文本文件中,我只是 - 你叫什么名字?
我不知道为什么会这样.也许这是我的问题,我将StreamReader重新开始?我检查了我的编码,一切,但没有任何效果.谢谢你的帮助 :)
PotentialEmployee potentialEmployee = new PotentialEmployee();
using (StreamReader InterviewQuestions = new StreamReader(text, Encoding.Unicode))
{
int totalLines = 0;
while (InterviewQuestions.ReadLine() != null)
{
totalLines++;
}
InterviewQuestions.DiscardBufferedData();
InterviewQuestions.BaseStream.Seek(0, SeekOrigin.Begin);
for (int numberOfQuestions = 0; numberOfQuestions < totalLines; numberOfQuestions++)
{
string question = InterviewQuestions.ReadLine();
Console.WriteLine(question);
string response = Console.ReadLine();
potentialEmployee.Responses.Add(question, response);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我在外部方法中进行TotalLines计算时,问号不会显示.有什么想法吗?