Home Backend Development C#.Net Tutorial 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

Mar 08, 2017 am 11:51 AM

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 };
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


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维 
                                         };
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

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
Copy after login

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Active Directory with C# Active Directory with C# Sep 03, 2024 pm 03:33 PM

Active Directory with C#

Access Modifiers in C# Access Modifiers in C# Sep 03, 2024 pm 03:24 PM

Access Modifiers in C#

Random Number Generator in C# Random Number Generator in C# Sep 03, 2024 pm 03:34 PM

Random Number Generator in C#

C# Data Grid View C# Data Grid View Sep 03, 2024 pm 03:32 PM

C# Data Grid View

C# StringReader C# StringReader Sep 03, 2024 pm 03:23 PM

C# StringReader

Patterns in C# Patterns in C# Sep 03, 2024 pm 03:33 PM

Patterns in C#

C# StringWriter C# StringWriter Sep 03, 2024 pm 03:23 PM

C# StringWriter

BinaryWriter in C# BinaryWriter in C# Sep 03, 2024 pm 03:22 PM

BinaryWriter in C#

See all articles