There is a list

List<string> lst = new List<string>(); 

Every 5 minutes I bring the data there.

In half an hour I write the data to the file and I want the file to have a limit on the number of lines. Suppose there are no more than 1000 lines in the file.

Question

How to logically think through logic without creating buffer tables, counting the current number, etc. How can I override the StreamWriter method? Say, is an elegant solution.

  • 3
    why not just count how many lines have already been written? - Grundy
  • 2
    And what will you do with the superfluous, if in the list of 1200 lines for example; throw out, write to the next file? - Mirdin

1 answer 1

It is possible so:

 List<string> lst = new List<string>(); List<string> save = new List<string>(); int count = 3; lst.Add("111"); lst.Add("222"); lst.Add("333"); lst.Add("444"); lst.Add("555"); save = lst.GetRange(0, count); lst.RemoveRange(0, count); 
  • Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky