The BitConverter class has a field IsLittleEndian which, according to the documentation:
Indicates the byte order (“endianness”) in which data is stored in this computer architecture.
I notice in Reflector that the field is hard-coded to true in the static constructor of BitConverter.
So my question is, do I need to take account of IsLittleEndian when using the BitConverter – in other words, are there any .Net implementations running on big-endian platforms? And if not, what was the purpose of the field in the first place?
The CLI standard does not proscribe any particular Endianness, so if you want your program to be portable, you should not depend on a particular byte order… unless of course in scenarios where a particular byte ordering is required, such as with some data exchange protocols (thanks to user The Moof for pointing this out).
I suspect that you saw a hard-coded value for
IsLittleEndianin Reflector because when you downloaded/installed the .NET Framework on your machine, that particular installation package was targeted at a particular platform (e.g. Intel x86, which is Little Endian).I could thus imagine that there are other installation packages of the .NET framework that have
IsLittleEndianhard-wired to return a different value, depending on the platform that particular installation targets.