代码之家  ›  专栏  ›  技术社区  ›  John

C中结构中的多维数组#

  •  5
  • John  · 技术社区  · 17 年前

    我试图将以下内容(为了可读性而缩短)转换为C#,但遇到了问题

    #define DISTMAX 10
    struct Distort {
      int    a_order;
      double a[DISTMAX][DISTMAX];
    };
    

    以下是我得到的(页面上方有一个define):

    const int DISTMAX = 10;
    struct Distort
    {
            int a_order;
            fixed double a[DISTMAX,DISTMAX];
    }
    

    我得到的错误是stimply Syntax error,由于我预期的一维数组的限制,]和[。

    1 回复  |  直到 17 年前
        1
  •  7
  •   Jon Skeet    17 年前

    unsafe struct Distort
    {
         int a_order;
         fixed double a[DISTMAX * DISTMAX];
    }
    

    然后做适当的算术运算得到各个值。