title: how to convert byte pointer to structure
body: <p>i am having a trouble converting a byte pointer to a structure (while it works implicitly when the byte pointer is the argument but it never work with casting to a new object)</p>
  
  <p>assume i've </p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential)]
      public struct x
      {
          public y;
          public zType;
      }
  </code></pre>
  
  <p>which is a sequential structure that will represent a byte[] so when i can assign that byte[] to this structure and use it like x.y without having to worry about offsets </p>
  
  <p>my problem is when i pass a byte pointer byte* ptr = byte[] to a method with this structure as parameter it works but when i try to cast it normally it doesn't work</p>
  
  <pre><code>//this example works fine
  
  {
    byte[] myByteArray = new byte[];
    fixed (byte* ptr = myByteArray)
    someMethod(ptr)
  }
  
  someMethod(x myStruct)
  
  
  //the next example however doesn't work
  {
    byte[] myByteArray = new byte[];
    fixed (byte* ptr = myByteArray)
    x myStruct = (myStruct)ptr
  }
  </code></pre>
  
  <p>i hope i make sense, any idea how to cast it ?</p>