public static unsafe void Main (string[] args) { var buffer = new byte[32]; fixed (byte *pBuffer = buffer) { Array.Clear(buffer, 0, 32); *((Packed1*)pBuffer) = new Packed1 { A = 1, B = 32 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed1*)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed1R*)pBuffer) = new Packed1R { A = 2, B = 33 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed1R*)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed8*)pBuffer) = new Packed8 { A = 3, B = 34 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed8*)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed8R*)pBuffer) = new Packed8R { A = 4, B = 35 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed8R*)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed32*)pBuffer) = new Packed32 { A = 5, B = 36 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed32*)pBuffer)); } }
public static unsafe void Main(string[] args) { var buffer = new byte[32]; fixed(byte *pBuffer = buffer) { Array.Clear(buffer, 0, 32); *((Packed1 *)pBuffer) = new Packed1 { A = 1, B = 32 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed1 *)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed1R *)pBuffer) = new Packed1R { A = 2, B = 33 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed1R *)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed8 *)pBuffer) = new Packed8 { A = 3, B = 34 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed8 *)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed8R *)pBuffer) = new Packed8R { A = 4, B = 35 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed8R *)pBuffer)); Array.Clear(buffer, 0, 32); *((Packed32 *)pBuffer) = new Packed32 { A = 5, B = 36 }; Util.PrintBytes(buffer); Console.WriteLine(*((Packed32 *)pBuffer)); } }