views:

566

answers:

1

I'm trying to convert the following (shortened for readability) to C# and running into problems

#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?

+6  A: 

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.

Jon Skeet
This confirms what I already suspected. Thanks.
John
Don't you need to mark it as unsafe as well?
Henk Holterman