I ‘ve problem with array in C#. I’m quite new in C# I’m used to do programs in java.
I’m trying to transfer this code from C++ to C#.
This is code in C++
typedef struct point_3d { // Structure for a 3-dimensional point (NEW)
double x, y, z;
} POINT_3D;
typedef struct bpatch { // Structure for a 3rd degree bezier patch (NEW)
POINT_3D anchors[4][4]; // 4x4 grid of anchor points
GLuint dlBPatch; // Display List for Bezier Patch
GLuint texture; // Texture for the patch
} BEZIER_PATCH;
I have struct Vector3 in C# which is float x,y,z (I don’t need double …)
Now I’m trying to make structure bpatch and I have problems with the declaration of array
[StructLayout(LayoutKind.Sequential)]
struct BPatch
{
Vector3[][] anchors = new Vector3[4][4]; //there is the problem
uint dblPatch; // I'll probably have to change this two lines but it doesn't matter now
uint texture;
}
what do I do wrong?? I need aray 4×4 in structure, its type should be structure Vector3 which is declared as float x, float y, float z.
Thanks
In C#, Vector3[][] is not a matrix but an array of arrays. So, you will need to do this:
Here’s some documentation from msdn http://msdn.microsoft.com/en-us/library/2s05feca.aspx
Another way, inline:
Hope it helps.