相关疑难解决方法(0)

如何找到2D阵列的大小?

如果我声明这个数组......

string[,] a = {
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
                  {"0", "1", "2"},
              };
Run Code Online (Sandbox Code Playgroud)

然后我可以测量长度

a.Length
Run Code Online (Sandbox Code Playgroud)

这是12.如何测量阵列的尺寸?如果我试试......

a[0].Length
Run Code Online (Sandbox Code Playgroud)

我得到Wrong number of indices inside []; expected 2.是什么赋予了?

.net c# arrays multidimensional-array

79
推荐指数
3
解决办法
8万
查看次数

double [,] type,如何获取行数?

我似乎得到一个奇怪的价值.

如何获取数组中的行数:

double[,] lookup = { {1,2,3}, {4,5,6} };
Run Code Online (Sandbox Code Playgroud)

输出应为2.

c# arrays

4
推荐指数
1
解决办法
797
查看次数

2-D阵列的行和列大小

下面列出的代码是为了帮助我在C#中找到二维数组的行和列大小,但在访问列长度时(GetLength(1)),我最终会得到一个IndexOutOfRangeException.我的查找类似于q-a,但无法确定列大小.

  List<List<int>> intLists = new List<List<int>>();
  for (int i = 0; i < 2; i++)
  {
    List<int> tempList = new List<int>();
    for (int j = 0; j < 5; j++)
      tempList.Add(j + 5+i);
    intLists.Add(tempList);
  }

  int[][] intArray = intLists.Select(Enumerable.ToArray).ToArray();

  Console.WriteLine("Dimension 0 Length = " + intArray[0].Length);
  Console.WriteLine("Dimension 1 Length = " + intArray[1].Length);
  Console.WriteLine("Dimension 0 Length = " + intArray.GetLength(0));
  //Console.WriteLine("Dimension 1 Length = " + intArray.GetLength(1));
Run Code Online (Sandbox Code Playgroud)

c# arrays c#-4.0

1
推荐指数
1
解决办法
3291
查看次数

标签 统计

arrays ×3

c# ×3

.net ×1

c#-4.0 ×1

multidimensional-array ×1