|
Initialising an Array |
![]()
|
"An array initialized with a range of numbers"
#(1 2 3 4 5 6 7 8 9)
(1 to: 100) asArray.
|
Use Display It (Ctrl+D) to display the result of each of the above expressions. Here are two different ways of creating an Array object and initialising it with some values.
| 1. | The first is what is called a "literal array". The Array object is built directly by the Smalltalk compiler and filled with the integers 1 through 9. |
| 2. | Obviously, if you want to create a larger array and initialise it then typing all of the numbers into a literal array will be rather clumsy and time-consuming. The second example shows how to create a range of numbers (an Interval object) and then ask this to convert this into an Array object using the #asArray converting message. |
Remember, to get back to these experiments just choose Help/First Splash in any Dolphin tool window. |