Skip to main content
added 110 characters in body; added 73 characters in body
Source Link
Darin Dimitrov
  • 1.0m
  • 276
  • 3.3k
  • 3k

A StreamReader will try to automatically detect the encoding of a file if there's a BOM when trying to read:

public class Program { static void Main(string[] args) { using (var reader = new StreamReader("foo.txt")) { // Make sure you read from the file or it won't be able // to guess the encoding var file = reader.ReadToEnd(); Console.WriteLine(reader.CurrentEncoding); } } } 

A StreamReader will try to automatically detect the encoding of a file if there's a BOM:

public class Program { static void Main(string[] args) { using (var reader = new StreamReader("foo.txt")) { Console.WriteLine(reader.CurrentEncoding); } } } 

A StreamReader will try to automatically detect the encoding of a file if there's a BOM when trying to read:

public class Program { static void Main(string[] args) { using (var reader = new StreamReader("foo.txt")) { // Make sure you read from the file or it won't be able // to guess the encoding var file = reader.ReadToEnd(); Console.WriteLine(reader.CurrentEncoding); } } } 
Source Link
Darin Dimitrov
  • 1.0m
  • 276
  • 3.3k
  • 3k

A StreamReader will try to automatically detect the encoding of a file if there's a BOM:

public class Program { static void Main(string[] args) { using (var reader = new StreamReader("foo.txt")) { Console.WriteLine(reader.CurrentEncoding); } } }