c# - 无法获得其中包含数组名称的二维数组的长度
问题描述
我无法获得其中包含其他数组名称的二维数组的长度。喜欢..
int[] a = { 1, 2, 3 };
int[] b = { 23, 4, 6 };
int[][] ab = { a, b };
int r = ab.GetLength(1);
解决方案
GetLength(1) 适用于二维数组,您有一个锯齿状数组(数组数组),所有数组只有一个维度。因此,您不能将 1 作为 GetLength 的参数
例如,我会:
int r = ab[1].Length; // the length of the 23,4,6 array
还:
ab.Length //it is 2, there are two 1D arrays in ab
我们称它为锯齿状,因为它不必在每个槽中具有相同长度的数组:
ab[0] = new int[]{1,2,3,4,5};
ab[1] = new int[]{1,2,3,4};
推荐阅读
- javascript - 通过AJAX发送动态绘制框的坐标
- python - 具有多个 cuda 版本的系统上的 tensorflow-gpu 安装问题
- javascript - 量角器 - 如何使用多重过滤器找出目标行
- java - 在匿名内部类中的字段上使用源注释?
- java - 将 Tomcat 配置为 Windows 服务时出现高 CPU 消耗问题
- php - 设置计划任务时格式不正确或超出范围错误
- azure - Azure SignalR API 添加到组
- javascript - 在 Node 中生成以毫秒为单位的时间戳
- swift - 截取 UIScrollView 可见区域的截图
- .net - 检查 Microsoft Edge 是否已打开