How to read a text file reversely with iterator in C#

后端 未结 11 1864
甜味超标
甜味超标 2020-11-22 04:05

I need to process a large file, around 400K lines and 200 M. But sometimes I have to process from bottom up. How can I use iterator (yield return) here? Basically I don\'t l

11条回答
  •  盖世英雄少女心
    2020-11-22 04:42

    I put the file into a list line by line, then used List.Reverse();

            StreamReader objReader = new StreamReader(filename);
            string sLine = "";
            ArrayList arrText = new ArrayList();
    
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                    arrText.Add(sLine);
            }
            objReader.Close();
    
    
            arrText.Reverse();
    
            foreach (string sOutput in arrText)
            {
    

    ...

提交回复
热议问题