Array Brief (C # Programming Guide)

Source: Internet
Author: User

You can store multiple variables of the same type in an array data structure. declaring an array by specifying the type of its elements

Type []arrayname;

1 classTestarraysclass2 {3     Static voidMain ()4     {5         //Declare a single-dimensional array one-dimensional arrays6         int[] Array1 =New int[5];7 8         //Declare and set array element values9         int[] Array2 =New int[] {1,3,5,7,9 };Ten  One         //Alternative Syntax A         int[] Array3 = {1,2,3,4,5,6 }; -  -         //Declare A and dimensional array multidimensional arrays the         int[,] multiDimensionalArray1 =New int[2,3]; -  -         //Declare and set array element values -         int[,] MultiDimensionalArray2 = {{1,2,3}, {4,5,6 } }; +  -         //Declare a jagged array interleaved +         int[] Jaggedarray =New int[6][]; A  at         //Set the values of the first array in the jagged array structure -jaggedarray[0] =New int[4] {1,2,3,4 }; -     } -}

Properties of the array:

When an array instance is created, the dimensions and the length of each dimension are established. These values cannot be changed during the lifetime of the instance.

The default value of a numeric array element is set to zero, and the default value of the reference element is set to NULL.

A jagged array is an array of arrays, so its elements are reference types and are initialized to null.

The index of the array is zero-based: The index of an array with n elements is from 0 to n-1.

Array elements can be of any type, including array types

Array Brief (C # Programming Guide)

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.