我在 C# 中遇到数组问题。我对 C# 很陌生,我习惯用 java 编写程序。 我正在尝试将此代码从 C++ 转移到 C#。 这是 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;
我在 C# 中有 struct Vector3,它是 float x,y,z (我不需要 double ...) 现在我正在尝试制作结构 bpatch,但我在数组声明方面遇到问题
[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;
}
我做错了什么?我需要结构体中的aray 4x4,其类型应该是结构体Vector3,其声明为float x,float y,float z。 谢谢
最佳答案
您可以使用:
Vector3[,] anchors = new Vector3[4,4];
关于.net - C# 结构体中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8689044/