ARRAY (System.Array)
• An array variable is declared as : data_type[] array_name example: int[] arrayInt;
• Arrays are reference types, regardless of the type of their elements
• This means that an array variable refers to an array instance on the heap and does not hold its array elements directly on the stack
• When an array variable is declared, its size is not specified
• Size of array is specified only when an array instance gets created using new keyword
• An array variable is instantiated as: arrayInt = new int[4];
• Size of an array instance does not have to be constant, it can be calculated at run time
• Getting array size at run time:
int size = int.Parse(Console.ReadLine());
int arrayInt = new int[size];
• It is possible to create an array with size 0
• Multi-dimensional arrays can be created as: int[ , ] table = new[4, 6];
No comments:
Post a Comment