阵列中的结构C# [英] array in struct C#

查看:170
本文介绍了阵列中的结构C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前的问题,阵列中的C#。我在C#很新我已经习惯了在Java中做节目。 我想从C ++转让本code到C#。 这是code在C ++

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;

我在C#这就是浮存X,Y,Z结构体Vector3类型(我不需要双...) 现在,我努力使结构bpatch和我有问题数组的声明

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; 

}

我该怎么办错了?我需要在结构上阿雷四轮驱动,它的类型应该是被声明为float X,浮动Y,浮动ž结构Vector3类型。 谢谢

what do I do wrong?? I need aray 4x4 in structure, its type should be structure Vector3 which is declared as float x, float y, float z. Thanks

推荐答案

在C#中,Vector3类型[] []不是矩阵而是一个数组的数组。所以,你需要这样做:

In C#, Vector3[][] is not a matrix but an array of arrays. So, you will need to do this:

anchors = new Vector3[4][];
for(var i=0;i<anchors.Length;i++)
    anchors[i] = new Vector3[4];

下面是从MSDN http://msdn.microsoft.com/en一些文档-us /库/ 2s05feca.aspx

另一种方式,内嵌:

Vector3[][] anchors = new Vector3[][]{new Vector3[4],new Vector3[4],new Vector3[4],new Vector3[4]};

希望它帮助。

Hope it helps.

这篇关于阵列中的结构C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆