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

后端 未结 11 1863
甜味超标
甜味超标 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:28

    You can read the file one character at a time backwards and cache all characters until you reach a carriage return and/or line feed.

    You then reverse the collected string and yeld it as a line.

提交回复
热议问题