Determine what line ending is used in a text file
问题 Whats the best way in C# to determine the line endings used in a text file (Unix, Windows, Mac)? 回答1: Notice that text files may have inconsistent line endings. Your program should not choke on that. Using ReadLine on a StreamReader (and similar methods) will take care of any possible line ending automatically. If you manually read lines from a file, make sure to accept any line endings, even if inconsistent. In practice, this is quite easy using the following algorithm: Scan ahead until you