public MyX ToStruct(byte [] ar)
    {
        byte[] data   = ar;      //= { 1, 0, 0, 0, 9, 8, 7 }; // IntValue = 1, Array = {9,8,7}
        IntPtr ptPoit = Marshal.AllocHGlobal(data.Length);

        Marshal.Copy(data, 0, ptPoit, data.Length);
        MyX x = (MyX)Marshal.PtrToStructure(ptPoit, typeof(MyX));

        Marshal.FreeHGlobal(ptPoit);
        return(x);
    }
Example #2
0
    public void SomeMethod()
    {
        MyValue = 42; // MyValue is in scope here, since it's a member of `MyY`,
                      // and we're in an instance method on `MyY`
        var myX = new MyX();

        myX.MyValue = 50; // MyValue must be qualified with an instance

        var myY = new MyY();

        myY.MyValue = 60; // MyValue must be qualified, otherwise `this` is implied
        var myself = this;

        Console.WriteLine(myself.MyValue); // Prints 42
    }