You can even initialize an anonymous array:
new int[] { 17, 19, 23, 29, 31, 37 }
This expression allocates a new array and fills it with the values inside the braces. It counts the number of initial values and sets the array size accordingly. You can use this syntax to reinitialize an array without creating a new variable. For example,
smallPrimes = new int[] { 17, 19, 23, 29, 31, 37 };
int[] anonymous = { 17, 19, 23, 29, 31, 37 };
smallPrimes = anonymous;
new
will create another array.
No comments:
Post a Comment