CSharp · Console
using System;
using System.Threading;
using System.Runtime.InteropServices;
namespace Program
{
public class Program
{
public static void Main(string[] args)
{
var array = new ByteArray();
array.Int = 0xBADF00D;
Console.WriteLine(array.Int);
Console.WriteLine(array.Byte1.ToString("X"));
Console.WriteLine(array.Byte2.ToString("X"));
Console.WriteLine(array.Byte3.ToString("X"));
Console.WriteLine(array.Byte4.ToString("X"));
}
}
}
[StructLayout(LayoutKind.Explicit)]
struct ByteArray
{
[FieldOffset(0)]
public byte Byte1;
[FieldOffset(1)]
public byte Byte2;
[FieldOffset(2)]
public byte Byte3;
[FieldOffset(3)]
public byte Byte4;
[FieldOffset(0)]
public int Int;
}