Attention to arrays (C #)

Source: Internet
Author: User

Array

An array is a data structure that contains several variables of the same type. Arrays are declared by type:

Type [] arrayname;

The following example creates a one-dimensional, multi-dimensional, and staggered array:

C # copyCode
Class testarraysclass
{
Static void main ()
{
// Declare a single-dimen1_array
Int [] array1 = new int [5];

// Declare and set array element values
Int [] array2 = new int [] {1, 3, 5, 7, 9 };

// Alternative syntax
Int [] array3 = {1, 2, 3, 4, 5, 6 };

// Declare a two dimen1_array
Int [,] multidimensionalarray1 = new int [2, 3];

// Declare and set array element values
Int [,] multidimensionalarray2 = {1, 2, 3}, {4, 5, 6 }};

// Declare a jarged Array
Int [] [] jaggedarray = new int [6] [];

// Set the values of the first array in the jarged Array Structure
Jargedarray [0] = new int [4] {1, 2, 3, 4 };
}
}

Array Overview
An array has the following attributes:

Arrays can be one-dimensional, multi-dimensional, or staggered.

The default value of the numeric array element is set to zero, and the default value of the referenced element is set to null.

An interleaved array is an array. Therefore, its element is of the reference type and its initialization is null.

The index of an array starts from zero: The index of an array with n elements ranges from 0 to n-1.

Array elements can be of any type, including arrays.

The array type is derived from the abstract base type array.Reference Type. Because this type implements ienumerable and ienumerable, you can use foreach Iteration for all arrays in C.

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.