Search code examples
c#c++bytejagged-arraysuint

Jagged Uint8 array convert to C# byte


I have a jagged uint8 array like this in c++:

UINT8 ras[2][3] = {{1,2,3},{4,5,6}}

I need some way to use this as a byte array in c#. Something like

byte[2][3] ras = {{1,2,3},{4,5,6}}

I have a lot of uint8 arrays, so doing it manually is not an option. Anya ideas?


Solution

  • If I understand the comments to your question above, you are simply missing a bit of C# syntax.

    The C# syntax would be:

    byte[][] ras = new byte[][] {new byte[] {1,2,3}, new byte[] {4,5,6}};
    

    It's quite a bit more verbose than the equivalent c++, but easily translated mechanically with sed.