網站首頁 編程語言 正文
如何獲取二維數組中的元素個數呢?
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
相關推薦
- 2023-03-29 Pytorch損失函數torch.nn.NLLLoss()的使用_python
- 2022-06-10 AJAX原理以及axios、fetch區別實例詳解_AJAX相關
- 2022-09-27 Android實現密碼隱藏和顯示_Android
- 2022-08-23 在Asp.net?core中實現websocket通信_實用技巧
- 2022-09-20 C語言數據結構之單鏈表操作詳解_C 語言
- 2022-11-17 C++11中異常處理機制詳解_C 語言
- 2022-11-25 Python利用memory_profiler實現內存分析_python
- 2022-09-10 Golang中Interface接口的三個特性_Golang
- 最近更新
-
- 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同步修改后的遠程分支