網站首頁 編程語言 正文
如何獲取二維數組中的元素個數呢?
int[,] array = new int[,] {{1,2,3},{4,5,6},{7,8,9}};//定義一個3行3列的二維數組 int row = array.Rank;//獲取維數,這里指行數 int col = array.GetLength(1);//獲取指定維度中的元素個數,這里也就是列數了。(0是第一維,1表示的是第二維) int col = array.GetUpperBound(0)+1;//獲取指定維度的索引上限,在加上一個1就是總數,這里表示二維數組的行數 int num = array.Length;//獲取整個二維數組的長度,即所有元的個數
根據上述我們可以自己驗證多維數組的形式,使用循環遍歷操作數組,例如下面的四維數組:
int[,,,] arr = new int[9, 8, 7, 6];
arr.Rank;//返回4 arr.GetLength(0);//返回9 arr.GetLength(1);//返回8 arr.GetLength(2);//返回7 arr.GetLength(3);//返回6 arr.GetUpperBound(0)+1;//返回9 arr.Length;//返回3024
剩下的循環遍歷數組并操作我就不需要解釋了吧,自己根據上面的數子進行操作。
原文鏈接:https://www.cnblogs.com/mq0036/p/5889220.html
相關推薦
- 2022-08-21 利用Python制作本地Excel的查詢與生成的程序問題_python
- 2022-06-29 python密碼學庫pynacl功能介紹_python
- 2022-01-08 使用grid布局解決flex布局最后一行不足的問題
- 2022-10-04 Python的getattr函數方法學習使用示例_python
- 2022-06-27 ABP引入Dapper框架的創建使用_實用技巧
- 2023-03-21 Golang使用Gin創建Restful?API的實現_Golang
- 2023-03-05 useCallback和useMemo的正確用法詳解_React
- 2022-06-09 忘記Grafana不要緊2種Grafana重置admin密碼方法詳細步驟_服務器其它
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支