New line character in c#

c#, newline

Solution

In Windows each new line consists of two characters `\r` and `\n`. You have 10 lines, each line have 1 visible characters and 2 new line characters which add up to 30 characters.

If you have created your file in Mac or Unix/Linux you would have gotton different result (20 characters). Because Unix uses only `\n` and Mac uses only `\r` for a new line.

You can use some editors (such as Notepad++) to show you new line characters, or even switch between different modes (DOS/Unix/Mac).

Problem

I wrote this code to count the number of characters in a text file : ``` sr.BaseStream.Position = 0; sr.DiscardBufferedData(); int Ccount = 0; while (sr.Peek() != -1) { sr.Read(); Ccount++; } ``` but after applying this code to a file contains : ``` 1 2 3 4 5 6 7 8 9 0 ``` Ccount = 30 ???? why? I am using Windows Xp on virtual box on my Macbook the program used : Microsoft Visual Basic 2010.

Original source