The problem is that the basic requirement is to sort the file rows in a specific order.
To solve the problem, you first read all the lines of the text, analyze them, sort them, write them back to the text file. In the following example, Insus. NET is slightly rewritten to a text file, which is only output on the page.
Download a file ds.txt, which is about the same as that of other users.
Insus. NET writes an object, that is, processing each row of a text file and converting each row into an object. In the following category, TryParse () is used to determine whether a text row meets the data analysis requirements. Obtain the correct values before and after the colon (:) When the class is applied.
The following describes how to read text files, obtain all rows, and sort them:
That is to say, when the second row is output, it is changed to the third line. Similarly, when the third row is output, it is changed to the second line, and the rest are output in normal order. You can see the final implementation result.