?? 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 + -