Array, collection, string manipulation, function summary

Source: Internet
Author: User

The array is stored in contiguous data of the same type.

One-dimensional arrays:

Definition: Data type [] Array name = new data type [array length];

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

For example: 1, int[] A = new int[5];

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

Question: The array length in Example 2 can not be written, please answer in the comments

Description

1. Data type [] indicates array type

Array names represent array variables

New represents the creation

data type [array length] array length cannot be empty (first definition)

2, array subscript: Used to determine the position of each element in the array, array subscript starting from 0

3, Array Assignment: array name [array subscript] = value Note data type is the same

4. Array values: variable = array name [array subscript] Note data types are the same

5, the array traversal:

      For loop traversal array       

Int[] A = new int[5];

for (int i = 0;i<a.length;i++) //a.length represents the length of the array

{ //need to be aware of the relationship between array length and subscript

Console.WriteLine (A[i]);

}

      foreach Traversal array       

Int[] A = new int[5];

foreach (int i in a)

{

Console.WriteLine (i);

}

How to see the blog: Array manipulation

Two-dimensional arrays

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

data type [,] array name = new data type [3,2]{{1,2},{2,3},{3,4}};

For example: int[,] a = new int[3,4];

......

Description: 1, noun interpretation of the same dimension array

2, array subscript the same dimension array

3, Array Assignment: data type [row subscript, column subscript] = value

a[0,0] = 1;

4, Array value: Data type [row subscript, column subscript]

5, the array traversal:

       For loop traversal array       

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

for (int i = 0;i<3;i++)

{

for (int j = 0;i<4;j++)

{

Console.WriteLine (A[i,j]);

}

}

How to read the blog: two-dimensional array manipulation

Jagged arrays: Arrays of arrays

Definition: First step: defining large arrays

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

......

Step three: Put the decimal group in a large array

A[0] = A1;

A[1] = A2;

......

Comparison of two-dimensional arrays with jagged arrays:

      

  

Array, collection, string manipulation, function summary

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.