Home  >  Article  >  Backend Development  >  Detailed introduction to using C# to describe data structure 2: Array graphic code example

Detailed introduction to using C# to describe data structure 2: Array graphic code example

黄舟
黄舟Original
2017-03-08 11:51:481673browse

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:

Detailed introduction to using C# to describe data structure 2: Array graphic code example

You can also check Baidu Brain Map:
http:/ /naotu.baidu.com/file/f879a94fe2163c365cc22f4e4bbcc7dc

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

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

2) Assign values ​​separately:

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

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


Detailed introduction to using C# to describe data structure 2: Array graphic code example


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

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

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;

Compare 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

Summary 1 Array must determine the number of elements in each dimension of the element when compiling. This 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.
 
Download address of Array mind map:
http://download.csdn.net/detail/daigualu/9772336
Test source code download address:
http://download.csdn. net/my


The above is the detailed content of Detailed introduction to using C# to describe data structure 2: Array graphic code example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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