I'm trying to convert the following (shortened for readability) to C# and running into problems
我正在尝试将以下内容(为了便于阅读而缩短)转换为C#并遇到问题
#define DISTMAX 10
struct Distort {
int a_order;
double a[DISTMAX][DISTMAX];
};
I thought in structs it was a simple case of using "fixed" however I'm still getting problems.
我认为在结构中这是一个使用“固定”的简单情况,但我仍然遇到问题。
Here's what I've got (With a define higher up the page):
这就是我所拥有的(在页面上方定义更高):
const int DISTMAX = 10;
struct Distort
{
int a_order;
fixed double a[DISTMAX,DISTMAX];
}
The error I get is stimply Syntax error that ] and [ are expected due to what I expect to be a limitation of a single dimension array.
我得到的错误是语法错误,而且[预计由于我期望的是单维数组的限制。
Is there a way around this?
有没有解决的办法?
1 个解决方案
#1
7
Fixed sized buffers can only be one-dimensional. You'll need to use:
固定大小的缓冲区只能是一维的。你需要使用:
unsafe struct Distort
{
int a_order;
fixed double a[DISTMAX * DISTMAX];
}
and then do appropriate arithmetic to get at individual values.
然后进行适当的算术以获得单个值。
#1
7
Fixed sized buffers can only be one-dimensional. You'll need to use:
固定大小的缓冲区只能是一维的。你需要使用:
unsafe struct Distort
{
int a_order;
fixed double a[DISTMAX * DISTMAX];
}
and then do appropriate arithmetic to get at individual values.
然后进行适当的算术以获得单个值。