Array: An array is a set of values of the same type that can be indexed to access the elements in the array.
Syntax for declaring an array: A. Data type [] array name; B. data type [] Array name = new data type [array size]; C.int [] arr = {1,3,4,5,5,3,}; By specifying a location index: arr[0]
Multidimensional arrays: The values of multiple linear arrays. GetLength () one dimension: int [] arr = new int[2]; Two-dimensional: int [,] arr = new int[3,5]; Three-dimensional: int [,,] arr = new int[2,4,5]; Multidimensional arrays use GetLength to get the length, and the dimension is also starting from 0.
Jagged array: "Array in array". () . Length declaration syntax: int [] arr = new Int[2][];//arr contains two elements int [0] = new int[2];//The first element is an array of two integers int [1] = new int[3];//second element An array of three integers is assigned: arr[0][0] = 100; A jagged array has better performance than a multidimensional array.
System.Array array: Declaration syntax: Array arr = array.createinstance (typeof (int), 3),//type int, length 3 typeof keyword for data type. ============================================================================== Using System.Collections Collection: Use Count to get the collection length. Hashtable collection: syntax: Hashtable name = new Hashtable (); Example: Hashtable hs = new Hashtable (); //Add HS. ADD (4, "Zhang San"); HS. ADD (6, "John Doe"); HS. ADD (7, "Harry"); //hs. Remove (4);//delete //console.writeline (HS. Count);//Get Set length Console.WriteLine (hs["Key"]) ;//Get key value &nbsP Console.WriteLine (hs["Values"]);//Get values //foreach traverse array Values foreach (Object lan in HS. Values) { Console.WriteLine (LAN. ToString ()); }
ArrayList collection: syntax: ArrayList name = new ArrayList (); Example: ArrayList al = new ArrayList (); //Add elements al. ADD (12); al. ADD ("Blue Sky"); al. ADD (3.14); al. RemoveAt (0);//The element Al that specifies the index position in the array list. Insert (0, "O (∩_∩) o haha ~");//Insert the index position specified in the array list remove: Removes the element. TrimToSize: Sets the capacity to the actual number of elements in ArrayList for (int i = 0 ; I < al. count;i++) { Console.WriteLine (Al[i]);//loop out all elements }
============================================================================== array differs from collection:
Arrays collections using length to get lengths Use count to get length Fixed length non-fixed length, can be added to delete (object) Difference data type fixed ( What type of value will be added to the application? object type (add any type arbitrarily) Direct assignment using Add for foreach system Collection under =============================================================== =============== Hashtable and ArrayList difference: Hashtable key value mapping, simply say the key corresponding value, we recognize each value from the name, key so-called name, we look for values by name, and ArrayList set, linear structure to store data, The collection stores the contents of all values, and we index each value with an index, and the process we use is indexed;
ArrayList orderly, but Hashtable disorder;
ArrayList can add and remove elements at specific locations, and Hashtable can only be added sequentially.
ArrayList index is 0 Hashtable object (custom) ============================================================================= = Nested loops: The outer loop is used to control the number of rows in the output, and the inner loop is used to control the number of columns in the output.
99 multiplication table for (int i = 0;i <= 9;i++) {for (int j = 0; J < i;j++) {Console.WriteLine (j+1) + "*" +i+ "=" + (i* (j+1)) + ""); } Console.WriteLine ("\ n"); }
Bubble sort: The ordering of array elements. (An algorithm)
Two-layer loop nesting: Outer loop N-1 Inner Loop n-1-i (N represents the length of an array or collection)
Example://Bubble sort int[] arrl = {3,6,2,7,9,12,4};//request array int temp;//define global variables for (int i = 0;i < ARRL. length-1;i++)//control The comparison of the number of trips, this cycle once to compare a trip { for (int w = 0; w < ARRL. Length-i-1; w++) { if (arrl[ W] < arrl[w+1]) { temp = arrl[w]; arrl[w] = arrl[w+1]; arrl[w+1] = temp; } } } foreach (int wy in ARRL)//iterate through the output sorted array { Console.WriteLine (WY); }
==============================================================================
Error Debug: try{//throws Exception//program code;}catch (Exception e) {//captures and handles exceptions. If there are multiple catch blocks, the parent class (Exception) must be in the back//exception handling code; CONSOLE.WRI Teline (e.message);//Displays the text Console.WriteLine (E.source) that describes the error condition,//Displays the name of the application or object that caused the exception Console.WriteLine (e.stacktrace );//provides the details of the method called in the stack, and the method that was first called recently. Console.WriteLine (e.innerexception);//provides access to internal exceptions.
} finally{//Final Processing}
Black box test: No matter what the code is, as long as the function can be achieved is successful. White box test: opposite the black box.
C # Getting Started basics three or four