【发布时间】:2013-09-02 20:27:27
【问题描述】:
我有一个学生的文本文件,我必须阅读它并将其保存在数组列表中。文件的格式是第一名,第二名,标记,每个名字都写在一个新行中,请帮我看看怎么做 文件格式:
First Name
Last Name
Marks
First Name
Last Name
Marks
First Name
Last Name
Marks
这是我迄今为止尝试过的:
List<string> fileContent = new List<string>();
TextReader tr = new StreamReader("A.txt");
string currentLine = string.Empty;
while ((currentLine = tr.ReadLine()) != null)
{
fileContent.Add(currentLine);
}
【问题讨论】:
-
有什么理由使用
ArrayList而不是List<T>?除此之外,您已经尝试过什么,出了什么问题?我们不会只为您做功课,但我们会帮助您找出您的尝试有什么问题。 -
常见的不是我的作业,我正在为一家公司工作,这是我现在面临的唯一问题,我无法弄清楚该怎么做列表会很好,但我不确定怎么做我已经试过了
-
List
fileContent = new List (); TextReader tr = new StreamReader("A.txt");字符串 currentLine = string.Empty; while ((currentLine = tr.ReadLine()) != null) { fileContent.Add(currentLine); } -
List
fileContent = new List (); TextReader tr = new StreamReader("A.txt");字符串 currentLine = string.Empty; while ((currentLine = tr.ReadLine()) != null) { fileContent.Add(currentLine); } -
用这个编辑问题,因为源代码在 cmets 中看起来很丑
标签: c# file list arraylist c#-3.0