I am trying to keep a data file but I'm getting confused with the sizeof(char) = 2 bytes. I understand that it is a unicode char but why does class BinaryReader's function ReadChars(int count) function just increases the streams position by count bytes ?

If that is not clear here is what I ask;

sizeof(char) = 2 OK!

when I say

BinaryReader fileReader = new BinaryReader(File.Open(fileName, FileMode.Open));
fileReader.ReadChars(100); // Here it increases the current stream position by 100 bytes , but it should be sizeof(char) * 100 = 200 bytes

It depends on how the file itself is encoded. If it's an ASCII encoding (UTF-8) then 100 bytes = 100 characters. And just to confuse the issue more, sizeof(char) can vary from 1 to 4 bytes depending on what unicode character is being represented. Most of the time you'll only see the 2 byte version, but there are a few odd characters that require more.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.