What is an array?
An array is an unordered sequence of elements, and all elements in an array have the same type.
Declaring an array variable:
Int[] A; the size of the array is not part of the Declaration;
To create an instance of an array:
A=new Int[3];
Initialize the array variable:
Int[] A=new int[2]{1,2};
Int[] a={1,2};
Time[] schedule={new time, New Time (5,30)};
To create an implicitly-typed array:
var name=new[]{new {name= "John", age=44},new {name= "Diana", age=45}};
To iterate over an array:
You can use a for statement, or a foreach statement, to define the type as var when you do not know the type of the array.
To copy an array:
int pins={9,3,7,2};
Int[] Copy=new int[pins. Length];
Pins.copyto (copy,0);
Use System.Array copy (source, copy to array, length of array);
Using multidimensional arrays:
int[,] items=new int[4,6];
What's the collection class:
The elements in the collection class are of type object, and the values are boxed directly when they are stored;
ArrayList Collection class:
There is an add (), remove () insert () method;
Queue Collection Class:
There are two methods of Enqueque and dequeue;
Stack Collection class:
There are two types of push and pop;
Hashtable Collection class:
Hashtable a =new hashtable ();
A["Z"]=23;
a["W"]=24;
Froeach (dictionaryentry element in ages)
{
String Name= (String) Element.key;
int age= (int) element.value;//unboxing for forced type conversions
}
SortedList and Hashtable use the same method;
C # Basic Grammar review-working with arrays and collections