C # Array

Source: Internet
Author: User

Notes for Arrays:

1. Same type: the data element types in the array are the same

2. Data element: the data items in the array can be of any type, and the data element type also represents the type of the array. Access array elements are accessed by array names and location indexes.

3. Ordered: array elements are indexed Based on locations, and the index starts from 0.

4. Set: An array is a set of data elements.

5. the array type belongs to the reference type.

6. The array is derived from the system. array type.

Array declaration:

Int [] arr1 = new int [5]; // specify the length of int [] arr2 = new int [5] {1, 2, 3, 4, 5}; // specify the length of the array and the element int [] arr = new int [5] {1, 2, 3, 4} at the same time. If this statement is used, an error is returned, the number specified during Declaration must be consistent with the length. // The code for this row and INT [] arr2 = new int [] {1, 2, 3, 4, 5}

In addition, because system. array implements the ienumerable and ienumerable <t> interfaces, you can use foreach for iteration.

Attributes and methods inherited from Array

I. Attributes

Member description

Length: the length of the array, that is, the total number of elements in all dimensions in the array.

Rank

Ii. Method

Member description

Binarysearch uses binary search algorithms to search for values in an array.

Clear sets some elements in the array to zero, false, or null, the reference type to null, And the integer to 0.

Clone shortest the Array

COPY Copies some elements in the array to another array.

Copyto copies all elements in one-dimensional array to another instantiated Array

Getlength returns the length of the specified dimension.

Getupperbound: returns the upper limit of the specified dimension.

Getvalue returns the value of the specified index position of the current array.

Indexof returns the index of the data matching the given value in a one-dimensional array.

Lastindexof is the same as indexof, but it is in reverse order.

Resize <t> changes the array size to the specified size. The principle is to create an array and copy the data from the original array to the new array.

Reverse reverses the order of some elements in a one-dimensional array.

Servalue sets a new value for the specified index location of the current array

Sort To sort elements in the array

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.