Properties and methods of arrays in C # (cont.)

Source: Internet
Author: User

A Properties of C # arrays

The properties and methods of one-dimensional arrays and multidimensional (two-dimensional or above) arrays are similar, mainly in the array methods, some of the parameters are inconsistent, now we first look at the next one-dimensional array of related properties;

Int[] Myint = new INT[5];

for (int x = 1; x <= 5 + x + +)

MYINT[X-1] = x;

Console.WriteLine ("Show data in Array");

for (int i = 1; I <= 5; i++)

Console.WriteLine ("The value of the {0} element is {1}", I, myint[i-1]);

Console.WriteLine ("Display the nature of the array");

Console.WriteLine (Myint. isfixedsize);//Whether fixed size

Console.WriteLine (Myint. ISREADONLY);//is read-only

Console.WriteLine (Myint. issynchronized);//whether to operate asynchronously

Console.WriteLine (Myint. length);//size of the array

Console.WriteLine (Myint. LONGLENGTH);//Length of array

Console.WriteLine (Myint. Rank);//number of dimensions of the array

Console.WriteLine (Myint. SyncRoot);//Array of objects

The running diagram is as follows:

The index number of an array element is 0, Myint[0] is the first element of the array, and its last element is myint[arraysize-1]. If the value of the index number is greater than or equal to the length of the array, an error exception occurs:

Two Methods provided by C # arrays

1. Common method of instance object

Console.WriteLine (Array.indexof (myint,3));

Gets the index number in the array of element 3 in the array

Console.WriteLine (Array.lastindexof (Myint, 3));

Gets the index number in the array of element 3 in the array, and finally matches the 3 in the array

Console.WriteLine (Array.asreadonly (Myint));

Array.reverse (Myint);//The element of the array

for (int i = 1; I <= 5; i++)

Console.WriteLine ("The value of the {0} element is {1}", I, myint[i-1]);

Console.WriteLine (Myint. GetLength (0));//Get the number of elements of the specified dimension

Console.WriteLine (Myint. Getlonglength (0));

Console.WriteLine (Myint. Getlowerbound (0));//Get the lower bound of the specified dimension;

Console.WriteLine (Myint. GetType ());//The type of the current instance object

Console.WriteLine (Myint. GetValue (2))//Get the value of the element whose index number is 2 in the array

Console.WriteLine (Myint. GetHashCode ());//Get the hash of the object

Console.WriteLine (Myint. ToString ());

Console.WriteLine (Myint. GetEnumerator ());//Get an enumeration of objects

Myint. SetValue (111,0);//set {Newvalue,index_of_array

Console.WriteLine (Myint[0]);

Console.WriteLine ("Clone Method");

Int[] Orignalarray = {1, 2, 3};

Int[] Clonearray = (int[]) Orignalarray.clone ()//Clone a new array

Clonearray[0] = 10;

CLONEARRAY[1] = 20;

CLONEARRAY[2] = 30;

foreach (int i in Orignalarray)

Console.WriteLine (i);

foreach (int i in Clonearray)

Console.WriteLine (i);

int[] Copyarr = new Int[myint. Length];

Myint. CopyTo (copyarr,0),//Copy an array to another array

Console.WriteLine ("{0},{1},{2},{3},{4}", Copyarr[0], copyarr[1], copyarr[2], copyarr[3], copyarr[4]);

Console.WriteLine ("{0},{1},{2},{3},{4}", Myint[0], myint[1], myint[2], myint[3], myint[4]);

int[] array_1 = new INT[5];

for (int i = array_1.getlowerbound (0); I <= array_1.getupperbound (0); i++)

Array_1[i] = i + 1;//get the lower bound of the specified number of dimensions to get the upper limit of the specified dimension

for (int j = array_1.getlowerbound (0); J <= Array_1.getupperbound (0); j + +)

Console.WriteLine ("array_1[{0}] = {1}", J, Array_1[j]);

The results of the program running are:

The next section details the static method of 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.