Non-computer professional C # study notes 5, arrays and collections

Source: Internet
Author: User

Array and set

1. array problem Array

(1) One-dimensional array: int [] arr = {1, 2, 3, 5} string [] S = {s, L, S, g}

(2) Two-dimensional array: int [,] arr = new int [2, 2] {1, 2}, {3, 4 }}

Type [,] array name = new type [number of rows (number of elements), number of columns (element prime number] {element 1, element 2 },{ element ...},...,}

L dynamic array: Type [,] array name = new type [M, N], int M = "; int n = "";

L view internal elements: foreach (int n in ARR) {console. Write (n );}

Sorting: Calendar (bubble); insertion; selection of sorting (see p109 and Cd content); array. sort (ARR) and; array. reverse (ARR) can be sorted by calendar

Int [] array = new int [*];

Int temp = 0;

For (INT I = 0; I <array. Length-1; I ++)

{

For (Int J = I + 1; j <array. length; j ++) // records all arr locations

{

If (array [J] <array [I])

{

Temp = array [I];

Array [I] = array [J];

Array [J] = temp;

}

}

}

Books:

Int [] arr = new int [] {3, 9, 27, 6, 18, 12, 21, 15 };

Foreach (INT m in ARR)

Int J, temp;

For (INT I = 0; I <arr. Length-1; I ++)

{

J = I + 1;

ID: // identify that the following code is a repeated execution process, so that you can use goto to continue execution without executing the foreach main method, that is, executing I ++ once in foreach, ID because goto can be executed multiple times

If (ARR [I]> arr [J])

{

Temp = arr [I];

Arr [I] = arr [J];

Arr [J] = temp;

Goto ID;

}

Else

If (j <arr. Length-1)

{

J ++;

Goto ID;

}

}

Foreach (int n in ARR)

Console. Write (n + "");

}

}

}}

 

L

L splitting and combination:

One-dimensional synthesis of one-dimensional-int Total = arr1.pen.pdf + arr2.length; int [,] totals = new int [total] {arr1arr2}; Value of arr1arr2: If the index is smaller than arr1, it is an arr1 element; if it is greater than arr1, it is an arr2 element.

N one-dimensional transformations of n-dimensional-int [,] arrs = new int [n, m] {…}; I <arrs. rank (<m), and then take one dimension as a layer of n-dimensional, switch (I), Case 0: arrs [I, L] = arr1 [J]…. Case1... Case N...

For details about splitting, see the "splitting arrays" project folder in the learning notes folder.

Knowledge Accumulation: Console. Write (); one row is written to the console; console. writeline () is written to the console according to the original data structure;

Arr. Length indicates the length of the array, the number of columns and the number of elements. Arr. rank indicates the number of layers and dimensions of the array.

2.ArrayArraylistThe class (key) is locatedSystem. CollectionsOnly one-dimensional arrays are allowed under the namespace, not equal to arrays.

(1) Basic Forms and attributes:

Arraylist alist = new arraylist (ARR); int [,] arr = new int [3] {1, 2, 3}, or assign a value after specifying the number of elements

Arraylist alist = new arraylist (3); For (INT I = 0; I <list. Count; I ++) {list. Add (I );}

Arraylist attributes: arraylist. capacity; quantity of capacity elements; count actual number of contained elements;

(2) Add list. Add to an element (the value of the element to be inserted at the end of the arraylist); list. insert (position from scratch, inserted content)

(3) Deletion of elements: List. Clear (): No parameter is required to delete all elements; List. Remove (an element );

List. removet (position); list. moverange (start position, number of elements to be deleted );

(4) calendar method of arraylist: foreach ....

(5) Search for specific elements: List. Contains (content or element to be searched );

3.Collection Problems----Hash tableHashtable

Hashtable HST = new hashtable ();

HST. Add (key-column name, value );

HST. Clear (); // delete all keys

HST. Remove (key-column name );

HST. Contains (key-column name); // you can check whether a specific key exists, without a value.

HST. containsvalue (value) // * check whether a specific value exists, excluding the key bit

Not to mention, I personally lament that mathematics is not very good. When dealing with some practical problems, it will have more or less an impact.

Non-computer professional C # study notes 5, arrays and collections

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.