Wednesday 4 January 2012

Custom types

The predefined types can be aggregated and extended into custom types.
Custom value types are declared with the struct or enum keyword. Likewise, custom reference types are declared with the class keyword.

Arrays
Although the number of dimensions is included in array declarations, the size of each dimension is not:
string[] s;
Assignments to an array variable (prior to the variable's usage), however, specify the size of each dimension:
s = new string[5];
As with other variable types, the declaration and the initialization can be combined:
string[] s = new string[5] ;
It is also important to note that like in Java, arrays are passed by reference, and not passed by value. For example, the following code snippet successfully swaps two elements in an integer array:
static void swap (int[] arr, int i, int j)
{
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}