示例#1
0
    public static unsafe void Main(string[] args)
    {
        var bytes = new byte[16];

        fixed(byte *pBytes = bytes)
        {
            var pStruct = (TwoIntFloatPairs *)pBytes;

            *pStruct = new TwoIntFloatPairs {
                A = new IntFloatPair {
                    Int   = 2,
                    Float = 3.5f
                },
                B = new IntFloatPair {
                    Int   = 16,
                    Float = -1.337f
                }
            };
        }

        for (var i = 0; i < bytes.Length; i++)
        {
            Console.Write("{0:X2} ", bytes[i]);
        }

        Console.WriteLine();
    }
    public static unsafe void Main (string[] args) {
        PackedArray[0] = new TwoIntFloatPairs {
            A = new IntFloatPair {
                Int = 1,
                Float = 2.22f
            },
            B = new IntFloatPair {
                Int = 2,
                Float = 3.33f
            }
        };
        PackedArray[1] = PackedArray[0];

        PackedArray[0].A.Int += 2;
        PackedArray[0].B.Float += 1.1f;
        PackedArray[1].B.Int += 3;

        foreach (var item in PackedArray)
            Console.WriteLine(item);
    }
示例#3
0
    public static unsafe void Main (string[] args) {
        var bytes = new byte[16];

        fixed (byte* pBytes = bytes) {
            var pStruct = (TwoIntFloatPairs*)pBytes;
            *pStruct = new TwoIntFloatPairs {
                A = new IntFloatPair {
                    Int = 2,
                    Float = 3.5f
                },
                B = new IntFloatPair {
                    Int = 16,
                    Float = -1.337f
                }
            };
        }

        for (var i = 0; i < bytes.Length; i++)
            Console.Write("{0:X2} ", bytes[i]);

        Console.WriteLine();
    }
示例#4
0
    public static unsafe void Main(string[] args)
    {
        PackedArray[0] = new TwoIntFloatPairs {
            A = new IntFloatPair {
                Int   = 1,
                Float = 2.22f
            },
            B = new IntFloatPair {
                Int   = 2,
                Float = 3.33f
            }
        };
        PackedArray[1] = PackedArray[0];

        PackedArray[0].A.Int   += 2;
        PackedArray[0].B.Float += 1.1f;
        PackedArray[1].B.Int   += 3;

        foreach (var item in PackedArray)
        {
            Console.WriteLine(item);
        }
    }