INITIALIZING ARRAY VARIABLES
• When an array instance is created, all the elements are initialized to a default value depending on their type
• This behavior can be modified by providing a comma separated list of values like:
int[] arrayInt = new int[4]{1,2,3,4};
• And runtime initialization is also possible, like:
Random r = new Random();
int[] arrayInt = new int[2]{ r.Next()%10, r.Next()};
• Array of structs would look like: Time[] Schedule = {new Time(12, 30), new Time(5,30)};
• IndexOutOfRangeException is thrown if element outside the size of array is accessed/modified
No comments:
Post a Comment