📄 readnews.cs
字号:
using System;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
public class News
{
string subject;
string author;
string contentFile;
public News(string subject,
string author,
string contentFile)
{
this.subject = subject;
this.author = author;
this.contentFile = contentFile;
}
public string Subject
{
get { return subject; }
}
public string Author
{
get { return author; }
}
public string ContentFile
{
get { return contentFile; }
}
public static ArrayList ReadNewsFromFile(string fileName)
{
StreamReader reader = null;
ArrayList list = new ArrayList();
try
{
reader = File.OpenText(fileName);
string line;
string[] words;
while( (line = reader.ReadLine()) != null)
{
words = Regex.Split(line, ",");
News news = new News(words[0], words[1], words[2]);
list.Add(news);
}
return list;
}
catch(FileNotFoundException e)
{
return list;
}
finally
{
if(reader != null)
reader.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -