One, array
1, one-dimensional array creation:
array element data type [] array name; such as Int[]arr; String[] arr;
2. Initialization of one-dimensional arrays
①int[] Arr=new int[3]; int[0]=1;int[1]=2;int[2]=3;
②int[] Arr=new int[]{1,2,3};
③int[]arr={1,2,3};
3, two-dimensional array creation:
① the array of data type [,] array name int[,]a=new int[2,4];2 row 4 column. Fit Rule Array
② data type [] [] array name int[][] a=new int[2][];int[0]=new int[2]; represents the first row two columns. Int[1]=new Int[3]; represents the second row of three columns. Note: This type of naming method cannot specify the number of columns. Specify the number of columns for each row before specifying the number of rows
4. Initialization of two-dimensional arrays
①int[,] arr=new int[2,2]; arr[0,0]=0;arr[0,1]=1;
②int[][] Arr=new int[2][]; Arr[0]=new int[]{0,1};arr[1]=new int[]{1,2}; Note: Rows are determined first, and each row is a one-dimensional array.
③int[,] arr=new int[2,2]{{12,0},{45,10}}; int[,] arr=new int[]{{12,0},{45,10}};int[,] arr={{12,0},{45,10}};
Ii. operation of arrays
1. Input and output of one-dimensional arrays: using single-layer loops
2. Two-dimensional array input and output: using double loop
3. The Foreach method iterates through the array: foreach (int number in arr)
4, array of sorts: ascending sort () from small to large, reverse () reverse sort;
5, Bubble Sort: The basic idea compares the adjacent two numbers, satisfies the condition, the smaller number rows in the array front, the larger number row after the array. Need to use a double loop,//Outer loop represents the comparison wheel number, 5 number to compare 4 rounds.//within the cycle from the comparison of the number of comparisons, the first round compared 4 times, the second round compared 3 times.
6. Select Sort: The basic idea is to exchange elements that satisfy the conditions with the position of the element at the specified position. The two-layer for loop implementation, the outer loop compares the number of wheels. Each round to find a minimum value for the position swap. The inner Loop finds the index of the minimum value.
Third, ArrayList class
1, ArrayList three kinds of constructors:
① using the default constructor
ArrayList list=new ArrayList ();
for (int i=0;i<10;i++) {list.add ()}
② is constructed with a Icolliction object
ArrayList list=new ArrayList (arryname)
③ Initializes an internal array with the specified size
ArrayList list=new ArrayList (n);
2, the addition of ArrayList elements
①add method adds an element at the end
②insert method Insert (index,value) index, value
3. ArrayList element deletion
①clear method to remove all elements
The ②remove method removes the first object of a specified object, remove (OBJ)
③removeat method RemoveAt (int index)
④removerange (index,count) index starts the number of indexes that count is removed
4. ArrayList traversal Array
foreach ()
5, ArrayList elements of the search
①contains method Contains (OBJ)
②indexof method returns the first occurrence of the location
③lastindexof method where the last occurrence of a match occurs
Four, Hashtable class
1, the addition of Hashtable elements
Add (Key,value) key key value
2. Hashtable element Removal
①clear method
②remove method Remove (key)
3, Hashtable traversal using the Dictionnaryentry type
4, Hashtable elements of the search
①contains method Contains (key)
②containsvalue method Containsvalue (value)
C # Getting Started basic grammar summary (Arrays and collections)