C # arrays

Source: Internet
Author: User

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

Type[] Arrayname;

The following example creates a one-dimensional, multidimensional, and jagged array:

1 classTestarraysclass2 {3     Static voidMain ()4     {5         //Declare a single-dimensional array6         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 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 +         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 }; -     } -}

Array overview

The array has the following properties:

    • An array can be one-dimensional, multidimensional, or interleaved.

    • 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.

    • An array element can be any type, including an array type.

    • An array type is a reference type derived from an abstract base type array. Because this type implements IEnumerable and IEnumerable, you can use foreach iterations for all arrays in C #.

C # 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.