C # file encoding type changed?

I create an encoding file ASCII, but when I test to get the encoding type of this file, it returns UTF8Encoding.

Can someone explain the cause or number of my mistake?

CODE:

File Creation:

 FileStream _textStream = File.Open("CreateAsciiFile.txt", FileMode.Create, FileAccess.Write);
 StreamWriter _streamWriter = new StreamWriter(_textStream, System.Text.Encoding.ASCII);

 Byte[] byteContent = BtyeTowrite();  // This returns the array of byte
 foreach(var myByte in byteContent)
    _streamWriter.Write(System.Convert.ToChar(myByte));

Reading file:

StreamReader sr = new StreamReader(@"C:\CreateAsciiFile.txt",true);
string LineText= sr.ReadLine();
System.Text.Encoding enc = sr.CurrentEncoding;

Here enc gives UTF8Encoding... But I expect ASCII???

+3
source share
2 answers

. sr.CurrentEncoding - . StreamReader , , ASCII , . , ( ) ASCII- a ISO-8859-1 .

+3

, , :"

ASCII Unicode UTF-8 .

, ASCII UTF-8 ASCII. UTF-8.

+1

All Articles