用 GetLength(int dimension) 获取数组指定维度的长度。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int[, ] arr = new int[2, 3]{ {1, 2, 3}, {4, 5, 6} };
// 可简写为 int[, ] arr = { {1, 2, 3}, {2, 4, 6} };
for (int i = 0; i < arr.GetLength(0); i++)
{
    for (int j = 0; j < arr.GetLength(1); j++)
    {
        Console.Write(arr[i, j]);
        Console.Write("\t");
    }
    Console.WriteLine();
}
/* 输出:
1    2    3
4    5    6
*/

 数组长度: num.Length

posted @   yinghualeihenmei  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· Obsidian + DeepSeek:免费 AI 助力你的知识管理,让你的笔记飞起来!
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2023-03-28 在 HTML 文档中使用 class 属性
2023-03-28 ztree 右键菜单功能
2023-03-28 js树形控件—zTree使用,右键出现菜单
2023-03-28 详解C# List<T>的Contains,Exists,Any,Where性能对比
2023-03-28 Request.url请求路径的一些属性
2023-03-28 C#中虚方法(virtual)详解
2023-03-28 C# override详解
点击右上角即可分享
微信分享提示