Why is BIGENDIAN a directive if it was not resolved at compile time?

Sorry for the poor wording, but I could not find a better way to explain this.

From my point of view, C # is the WORA language - you can write it on one computer and deploy it on another, since MSIL will not compile until the application is launched.

So why exactly is BitConverter.IsLittleEndian defined like this :

 #if BIGENDIAN public static readonly bool IsLittleEndian /* = false*/; #else public static readonly bool IsLittleEndian = true; #endif 

BIGENDIAN Here is the preprocessor directive, which means that it was resolved at compile time. So if the development machine is slightly end-oriented and the target uses a large endian, will IsLittleEndian still report true on the target machine?

+5
source share
1 answer

No, it will work as expected. The reason this will work is because the .NET runtime installed on the target system was created / compiled for this target system, so the BitConverter.IsLittleEndian property will return false . Your code simply refers to this property, so it is not determined until runtime.

+3
source

Source: https://habr.com/ru/post/1232130/


All Articles