public static void ByteOffsetStackByte4() { var byte4 = new Byte4(); Assert.Equal(new IntPtr(0), UnsafeIn.ByteOffset(byte4.B0, byte4.B0)); Assert.Equal(new IntPtr(1), UnsafeIn.ByteOffset(byte4.B0, byte4.B1)); Assert.Equal(new IntPtr(-1), UnsafeIn.ByteOffset(byte4.B1, byte4.B0)); Assert.Equal(new IntPtr(2), UnsafeIn.ByteOffset(byte4.B0, byte4.B2)); Assert.Equal(new IntPtr(-2), UnsafeIn.ByteOffset(byte4.B2, byte4.B0)); Assert.Equal(new IntPtr(3), UnsafeIn.ByteOffset(byte4.B0, byte4.B3)); Assert.Equal(new IntPtr(-3), UnsafeIn.ByteOffset(byte4.B3, byte4.B0)); }
public static void ByteOffsetArray() { var a = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }; Assert.Equal(new IntPtr(0), UnsafeIn.ByteOffset(a[0], a[0])); Assert.Equal(new IntPtr(1), UnsafeIn.ByteOffset(a[0], a[1])); Assert.Equal(new IntPtr(-1), UnsafeIn.ByteOffset(a[1], a[0])); Assert.Equal(new IntPtr(2), UnsafeIn.ByteOffset(a[0], a[2])); Assert.Equal(new IntPtr(-2), UnsafeIn.ByteOffset(a[2], a[0])); Assert.Equal(new IntPtr(3), UnsafeIn.ByteOffset(a[0], a[3])); Assert.Equal(new IntPtr(4), UnsafeIn.ByteOffset(a[0], a[4])); Assert.Equal(new IntPtr(5), UnsafeIn.ByteOffset(a[0], a[5])); Assert.Equal(new IntPtr(6), UnsafeIn.ByteOffset(a[0], a[6])); Assert.Equal(new IntPtr(7), UnsafeIn.ByteOffset(a[0], a[7])); }