当前位置:网站首页>Attribute acquisition method and operation notes of C # multidimensional array
Attribute acquisition method and operation notes of C # multidimensional array
2022-07-02 11:23:00 【chengjl8】
C# Provides various attribute acquisition methods for multidimensional arrays , But its expression is different from our habits , therefore , It also took some brains , I didn't understand it until I wrote some code tests , Now let's share :
1、 One dimensional array
A one-dimensional array is a combination of data with one row and multiple columns , It will be explained in the two-dimensional array later .
2、 Two dimensional array
We define a two-dimensional array as follows :
double[,] array1 = new double[3, 6];//2 Dimension group
Its image structure is as follows , here : dimension =2; The first 1 Dimensions are rows , Here for 3; The second dimension is the number of columns per row , Here for 6.
| 0 | 1 | 2 | 3 | 4 | 5 | |
| The first 0 That's ok | ||||||
| The first 1 That's ok | ||||||
| The first 2 That's ok |
here , Get the attributes and results of the array with code as follows ( The indexes are all from 0 Start ):
double[,] array1 = new double[3, 6];//2 Dimension group
int a = array1.Rank;// dimension =2
a = array1.GetLength(0);// For the first 0 The number of elements of dimension =3
a = array1.GetLength(1);// For the first 1 The number of elements of dimension =6
a = array1.GetLowerBound(0);// For the first 0 The first element index of the dimension =0
a = array1.GetUpperBound(0);// For the first 0 Index of the last element of the dimension =2
a = array1.GetLowerBound(1);// For the first 0 The first element index of the dimension =0
a = array1.GetUpperBound(1);// For the first 1 Index of the last element of the dimension =5
a = array1.Length;// Get the total number of elements =18
3、 Three dimensional array
We define a three-dimensional array as follows :
double[,,] array2 = new double[2, 3, 6];//3 Dimension group
Its image structure is as follows , here : dimension =3; The first 1 Three dimensional layers , Here for 2, The first 2 Dimensions are rows , Here for 3; The first 3 The first dimension is the column of each row , Here for 6.

double[,,] array2 = new double[2, 3, 6];//3 Dimension group
a = array2.Rank;// dimension =3
a = array2.GetLength(0);// For the first 0 The number of elements of dimension =2
a = array2.GetLength(1);// For the first 1 The number of elements of dimension =3
a = array2.GetLength(2);// For the first 2 The number of elements of dimension =6
a = array2.Length;// Get the total number of elements =364、 More dimensions
So do more dimensions , It's just adding a few more commas to the definition [,,,,,,,], But be careful : The number of elements increases exponentially .
5、 Attention to operation
- Array operation is much faster than list , If possible , Just use this array structure .
- The efficient method of traversing an array is multi-layer for loop , The higher the dimension number, the more internal circulation ( See below ), On the contrary, the efficiency decreases :
for(int i = 0; i < 3; i++) { for(int j = 0; j < 6; j++) { array1[i, j] = -1; } }
边栏推荐
- mysql 基本语句
- [AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
- ROS lacks xacro package
- Eight sorting summaries
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- Importerror: impossible d'importer le nom « graph» de « graphviz»
- 数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
- 在网上开股票账户安全吗?我是新手,还请指导
- Complement (Mathematical Simulation
- [paid promotion] collection of frequently asked questions, recommended list FAQ
猜你喜欢
![Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)](/img/dc/2aa55c9b3f23c292820a56ea72fedd.png)
Luogu p5536 [xr-3] core city (greed + tree DP looking for the center of the tree)

PHP tea sales and shopping online store

Eight sorting summaries

Why does LabVIEW lose precision in floating point numbers

数字化转型挂帅复产复工,线上线下全融合重建商业逻辑

CentOS8之mysql基本用法

一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)

mysql链表数据存储查询排序问题

【IDEA】使用插件一键逆向生成代码

2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
随机推荐
webauthn——官方开发文档
What are the software product management systems? Inventory of 12 best product management tools
The most detailed MySQL installation tutorial
金山云——2023届暑期实习
From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
STM32单片机编程学习
一.STM32的开发环境,keil5/MDK5.14安装教程(附下载链接)
The difference between self and static in PHP in methods
How to transfer event objects and user-defined parameters simultaneously in Huawei express applications
启牛商学院给的股票账户安全吗?能开户吗?
QT learning diary 7 - qmainwindow
原生方法合并word
The difference between SQL left join main table restrictions written after on and where
spritejs
flink二開,實現了個 batch lookup join(附源碼)
One trick to quickly realize custom application titlebar
QT learning diary 8 - resource file addition
Iii. Système de démarrage et d'horloge à puce
Openmldb meetup No.4 meeting minutes
[cloud native] 2.5 kubernetes core practice (Part 2)