title: C# Pointer: error CS0254: The right hand side of a fixed statement assignment may not be a cast expression
body: <p>I have a c++ server and now a trying to make a c# client.</p>
  
  <p>In c++, to send a packet I make this:</p>
  
  <pre><code>PMessage *msg = (PMessage*)&amp;buf[0];
  msg-&gt;id = PID_LOGIN;
  sendto(sServer, buf, sizeof(buf), 0, (SOCKADDR*)&amp;from, fromlen);
  </code></pre>
  
  <p>in c# I trying this:</p>
  
  <pre><code>unsafe
  {
      try
      {
          byte[] rawdata = new byte[Marshal.SizeOf(typeof(PMessage))];
  
          fixed (PMessage* p = (PMessage*)&amp;rawdata[0])
          {
  
          //     p-&gt;id = 1001;
          }
          udpClient.Send(rawdata, rawdata.Length); ;
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.ToString());
      }
  }
  </code></pre>
  
  <p>The compiler show this error:</p>
  
  <blockquote>
    <p>error CS0254: The right hand side of a fixed statement assignment may not be a cast expression.</p>
  </blockquote>
  
  <p>c#:</p>
  
  <pre><code>[StructLayout(LayoutKind.Sequential, Pack = 1)]
   unsafe struct PMessage
  {
      public  fixed byte msg[256];
      public int id;
      public int size;
  }
  </code></pre>
  
  <p>c++:</p>
  
  <pre><code>   struct PMessage
      {
          char msg[256];
          unsigned int id;
          unsigned int size;
      };
  </code></pre>