Home > Backend Development > C#.Net Tutorial > .NET Framework-Detailed introduction to Array

.NET Framework-Detailed introduction to Array

黄舟
Release: 2017-03-18 11:41:26
Original
1958 people have browsed it



 Array is the most basic data collection provided by .NET, which directly accesses collection elements through indexes. Provides one-dimensional or multi-dimensional data storage and supports operations such as query, search, sorting, copying, etc. The main interfaces provided by
are divided according to semantics, mainly including:

.NET Framework-Detailed introduction to Array

You can also view it on Baidu Brain Map:
http://naotu.baidu.com /file/f879a94fe2163c365cc22f4e4bbcc7dc

 One-dimensional arrayDeclaration, creation, initialization:
1) Directly in the initializer:

           int[] mp = new int[6] { -50, -30, -10, 10, 30, 50 };
Copy after login

2) Assign values ​​separately:

            mp[0] = -50;
            mp[1] = -30;
            mp[2] = -10;
            mp[3] = 10;
            mp[4] = 30;
            mp[5] = 50;
Copy after login

As shown in the figure below, the numbers of the one-dimensional graphs are 0,1,2,3,4,5 respectively


.NET Framework-Detailed introduction to Array
##Multidimensional (such as two-dimensional) array declaration, creation, initialization: (As shown in the figure above, the two-dimensional numbers are 0, 1, 2, 3, 4, 5 respectively)

            int[,] point = new int[2, 6] {
             { -50, -30, -10, 10, 30, 50 },//第0维
             { 50, 30, 10, 10, 30, 50 }//第1维 
                                         };
Copy after login

Initialization respectively:

            //点0
            point[0, 0] = -50;            point[1, 0] = 50;            //点1
            point[0, 1] = -30;            point[1, 1] = 30;            //点2
            point[0, 2] = -10;            point[1, 2] = 10;            //点3
            point[0, 3] = 10;            point[1, 3] = 10;            //点4
            point[0, 4] = 30;            point[1, 4] = 30;            //点5
            point[0, 5] = 50;            point[1, 5] = 50;
Copy after login

Comparison of one-dimensional and multi-dimensional, semantic differences of interface methods:

            //获取某维的元素个数
            int mpLen0 = mp.GetLength(0);//6
            int pointLen0 = point.GetLength(0);//2
            int pointLen1 = point.GetLength(1);//6

            //获取某个维度的下标最大值
            int mpUpperBound = mp.GetUpperBound(0); //5
            int pointUpperBound0 = point.GetUpperBound(0);//1
            int pointUpperBound1 = point.GetUpperBound(1);//5
            //获取某个维度的下标最小值
            int mpLowBound = mp.GetLowerBound(0);//0
            int pointLowBound0 = point.GetLowerBound(0);//0
            int pointLowBound1 = point.GetLowerBound(1);//0

            //获取所有维数的元素总数
            int mpLen = mp.Length;//6
            int pointLen = point.Length;//12
            //获取维数
            int mpRank = mp.Rank;//1
            int pointRank = point.Rank;//2
Copy after login

Summary 1 Array elements must be determined at compile time The number of elements in each dimension is its biggest flaw. For situations where the number of elements in a certain dimension can only be determined at runtime, this data structure cannot meet the conditions!
 2 The type of Array when it is created is a strong type and must be specified.
 

The above is the detailed content of .NET Framework-Detailed introduction to Array. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template