C # One-dimensional arrays, two-dimensional arrays, multidimensional arrays

Source: Internet
Author: User

The so-called array, which is the set of elements of the same data type, is arranged in a certain number of numbers, that is, a variable of the same type is named with a name, and then the set of the variable is distinguished by the number, the name becomes the array name, and the number is called the subscript. The variables that make up the array are the components of the array, also known as the elements of the array, sometimes referred to as subscript variables, which are in the program design and, for ease of handling, a form of organizing several variables of the same type in an orderly form. The collection of these ordered, homogeneous data elements becomes an array.

Arrays are also divided into one-dimensional arrays, two-dimensional arrays, multidimensional arrays

A one-dimensional array is indexed by an integer, and the multidimensional array is indexed by two or more integers.

One, data type [] Variable name = new data type [length];

II, string[] sss = new string[] {"AAA", "BBB", "CCC", "ddd", "Eee", "FFF"};

III, string[] sss = new String[5] {"AAA", "BBB", "CCC", "ddd", "Eee"};

Assignment variable name [index] = value of one-dimensional array;

The value variable of one-dimensional array = variable name [index];

int A;            int[] sz = new Int[3] {1, 5, 7};//define an array            a = sz[0];//define an empty variable to swap the first variable out            sz[0] = sz[2];//Change the first variable to a third            sz[2] = a ;//Replace the third one with the first for            (int i = 0; i < sz. Length; i++)                Console.Write (Sz[i]);                Console.ReadLine ()

  

Two-dimensional arrays:

int []a=new string[2,2]{{1,2},{3,4}};

This is a two-dimensional array, [2,2] the first 2 in parentheses means there are two one-dimensional arrays, and the 2nd 2 means that there are two variables in a one-dimensional array

three-dimensional array : Int[]a=new string[2,2,2]{{{1,2},{3,4}},{{5,6},{7,8}};

Three-dimensional array "2,2,2"

The first represents a total of 2 two-dimensional arrays, and the second 2 indicates that each of the two-dimensional arrays has two one-dimensional arrays;

C # One-dimensional arrays, two-dimensional arrays, multidimensional arrays

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.