簡體   English   中英

C# 結構中的多維 Arrays

[英]Multidimensional Arrays in a struct in C#

我正在嘗試將以下內容(為便於閱讀而縮短)轉換為 C# 並遇到問題

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

我認為在結構中這是使用“固定”的簡單案例,但是我仍然遇到問題。

這是我所擁有的(在頁面上方有一個定義):

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

我得到的錯誤是由於我期望是單維數組的限制而導致 ] 和 [ 的語法錯誤。

有沒有解決的辦法?

固定大小的緩沖區只能是一維的。 您需要使用:

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

然后進行適當的算術運算以獲得各個值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM