2013-09-27 35 views
0

我想從App_Data文件夾的實習txt文件中獲取一個ArrayList。如何從App_Data的實習txt文件中獲取ArrayList?

我在我的ASP.NET應用程序App_Data文件夾機智文件此內容如何:

P1 
AS5050 
GMS4010 
GMS4020 
GMS4030 
GMS4030A 
gateway 
view_only 
AS5050 

,我想這個名單中ArraList。

+0

你嘗試過什麼? –

+0

如果此數據P1 AS5050與\ r \ n分隔符分隔,則File.ReadAllLines將爲您提供字符串ArrayList – dbw

+0

不要再使用'ArrayList'。它屬於過去C#沒有_generics_的日子。改爲使用'List '。 –

回答

2
var result = new ArrayList(File.ReadAllLines(pathToYourfile)); 

但是......爲什麼一個ArrayList?通用名單在2013年會更好!

1

試試這個

ArrayList al = new ArrayList(File.ReadAllLines(path)); 

,但我會強烈建議List<T>超過ArrayList除非你使用.NET 1.0或1.1

List<string> list = new List<string>(File.ReadAllLines(path));