1. 程式人生 > >一行一行讀取TXT資料並返回List

一行一行讀取TXT資料並返回List

public static List<string> ReadList(string path, System.Text.Encoding encode)
        {
            List<string> result = new List<string>();
            string s = "";
            using (StreamReader sr = new StreamReader(path, encode))
            {
                while ((s = sr.ReadLine()) != null)
                {
                    result.Add(s);
                }
            }
            return result;
        }