Two-dimensional arrays

Source: Internet
Author: User
Tags array definition

One-dimensional array definition:

data type [] Array name = new data type [array length];

data type [] Array name = new data type [array length]{1,2,3 ...};

Two-dimensional array definitions:

data type [,] array name = new data type [number of rows, number of columns];

int[,] a = new int[3,4];

Assignment: a[row subscript, column subscript] = value subscript is starting from 0

Value: a[row subscript, column subscript]

Jagged data, an array of array definitions:

The first step: Define a large group

data type [] A = new data type [number of rows] []; Number of columns not written

Step two: Define the decimal group

Data type [] a1 = new data type [number of columns];

Data type [] a2 = new data type [number of columns];

......

Part III: Placing decimal groups in large arrays

A[0] = A1;

A[1] = A2;

......

Two-dimensional arrays and jagged arrays:

int[,] a = new int [3][4]; Wrong
Int[][] A = new int[3,4];//error
Int[][] A = new int[3][4];//error
int[,] C = new int[3,4];//pair

C.length = = ;

Int[][] A = new int[3][];

int[] A1 = new int[] {3, 4, 5, 6, 7};
int[] A2 = new int[] {1, 2, 3};
int[] a3 = new int[] {7, 8, 9, 10};

A[0] = A1;
A[1] = A2;
A[2] = A3;
A.length = = 3;

Two-dimensional arrays

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.