Here's a (cheap) solution that will work for both conversions.
[StructLayout(LayoutKind.Explicit)]
public struct UnionInt64Int32 {
public UnionInt64Int32(Int64 value) {
Value32H = 0; Value32L = 0;
Value64 = value;
}
public UnionInt64Int32(Int32 value1, Int32 value2) {
Value64 = 0;
Value32H = value1; Value32L = value2;
}
[FieldOffset(0)] public Int64 Value64;
[FieldOffset(0)] public Int32 Value32H;
[FieldOffset(4)] public Int32 Value32L;
}
The obvious flaw of this, though, is it is incapable. Values Value32H and value32L will change on different end platforms.
source
share