Alex Rivera | Logout

What does "The .NET framework uses the UTF-16 encoding standard by default" mean?

Asked 2009-03-23T23:44:48.047
17

My study guide (for 70-536 exam) says this twice in the text and encoding chapter, which is right after the IO chapter.

All the examples so far are to do with simple file access using FileStream and StreamWriter.

It aslo says stuff like "If you don't know what encoding to use when you create a file, don't specify one and .NET will use UTF16" and "Specify different encodings using Stream constructor overloads".

Never mind the fact that the actual overloads are on the StreamWriter class but hey, whatever.

I am looking at StreamWriter right now in reflector and I am certain I can see that the default is actaully UTF8NoBOM.

But none of this is listed in the errata. It's an old book (cheked the errat of both editions) so if it was wrong I would have thought someone had picked up on it.....

Makes me think maybe I didn't understand it.

So.....any ideas what it is talking about? Some other place where there is a default?

It's just totally confused me.

Edit
Report

1 Answer

3

Test it. Write the string "abcd" to a file. If it uses UTF8, the file will have a size of 4 bytes. Under UTF16, it'll be 8 bytes. (plus perhaps the BOM)

answered 2009-03-23T23:49:31.717

Your Answer