15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

348<br />

Using a Collection<br />

1 2<br />

Billy Joe 99<br />

3 4<br />

Johnny McGruffin Hal Perkins<br />

Figure 3-2:<br />

You can<br />

insert data<br />

be<strong>for</strong>e a<br />

specific<br />

location in<br />

an array.<br />

1<br />

2<br />

Billy Joe 3.14<br />

Adding new data in the middle of a collection<br />

automatically renumbers the rest of the collection.<br />

3 4 5<br />

99 Johnny McGruffin Hal Perkins<br />

This command would insert the name Gini Belkins after the third element<br />

in the collection, as shown in Figure 3-3.<br />

Figure 3-3:<br />

You can<br />

insert new<br />

data after<br />

an existing<br />

location in a<br />

collection.<br />

1 2<br />

Billy Joe 3.14<br />

1<br />

2<br />

Billy Joe 3.14<br />

Gini Belkins<br />

Inserting new data after the third<br />

item in a collection.<br />

3 4 5<br />

99 Johnny McGruffin Hal Perkins<br />

3 4 5 6<br />

99 Gini Belkins Johnny McGruffin Hal Perkins<br />

Don’t worry about the extra spaces between the three commas in the preceding<br />

command:<br />

✦ The first extra space is reserved <strong>for</strong> using collections with keys (which<br />

you read about later in this chapter).<br />

✦ The second extra space is used to store data be<strong>for</strong>e a location in a<br />

collection.<br />

Deleting data from a collection<br />

After you store data in a collection, you can always delete data from that collection.<br />

To delete data, you must specify the location of that data by defining<br />

an index number. So if you want to delete the fourth item in a collection,<br />

you’d specify deleting data stored at index 4 like this:<br />

HitList.Remove (4)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!