Knowledge (5): array and knowledge Array
Array:
Int [] intArray = new int [6];
Int [] [] intArray = new int [2] [];
Int [] [] [] intArray = new int [2] [] [];
IntArray [1] [2] [1] = 3;
Int [,] myTable = new int [2, 3];
MyTable [1, 3] = 3;
The Length attribute contains the number of elements in each dimension of the array.
The GetLength () method returns the number of elements in one dimension of the array.
The GetUpperBound () method provides a one-dimensional Index for the array.
The GetUpperBound () method is used to deploy a one-dimensional Index of the array.
ArrayList:
A set similar to an array. It can dynamically change the number of set elements.
Public class array
{
ArrayList AL = new ArrayList ();
Public void add ()
{
AL. Add ("lsdkjf ");
AL. Add (8 );
}
}
Count gets the number of elements in the set.
Add an element at the end of Add (object.
Remove (object) removes an element.
RemoveAt (int) removes the elements specified by the index in the set.
Insert (int, object) specifies the element to be added to the index.
Clear () removes all elements.
Contains (object) returns a Boolean value indicating whether the specified element is contained.
Copy the elements in the CopyTo () set to the specified set. You can specify the starting element.
IndexOf (object) returns the location where the specified element appears for the first time. If no such element exists,-1 is returned.
LastIndexOf (object) returns the position where the specified element appears at the most time. If not,-1 is returned.
ToArray () returns an array of the object type, which contains all elements in the ArrayList set.
TrimToSize () sets the value of the Capacity attribute to the actual number of elements in the current ArrayList set.
Stack collection Processing Stack
Stack (Stack set) follows the following principles: first-in-first-out. (From top to bottom)
Stack s = new Stack ();
S. Push (2 );
Push (object) to stack.
Number of elements in the Count stack.
Pop () removes and returns the elements at the top of the Stack. (That is, the most pressed element, at the top)
Peek () returns the object at the top of the Stack but does not remove it. (Same as Pop, output the last pressed element, at the top)
Queue set processing Queue:
The Queue (heap set) follows the FIFO principle.
Queue q = new Queue ();
Q. Enqueue (3 );
Enqueue (object) adds the object to the end of the Queue.
Dequeue () is removed and the object at the top of the Queue is returned.
Peek () returns the object at the top of the Queue, but does not remove the object.
Count the number of elements in the heap.
HashTable:
The HashTable set is stored as a key-value pair.
HashTable ht = new HashTable ();
Ht. Add ("01", "hhilbert ");
Use the index "[]" to retrieve elements in HashTable.
For example, object obj = ht ["01"]
Add (object, object) to the HashTable set. (Key, value)
Remove (object) removes the object of the specified key.
SortedList class:
Elements in the SortedList set are sorted based on their corresponding key values. You can use integer values to index the elements in the set.
SortedList SL = new SortedList ();
SL. Add (1, "hhht ");
The method property is similar to that of HashTable.