We often want to know how many items an array contains. We can do this with the .Length
property.
int[] plantHeights = { 3, 4, 6 }; // arrayLength will be 3 int arrayLength = plantHeights.Length
Using the .Length
property will return the number of items in an array and zero if the array is empty.
Instructions
Each playlist can only have eight songs, so we want to write a program that checks to make sure that there are the right amount of songs.
If there are eight songs in the playlist, have the console print out a message that lets the user know the playlist is complete, like “summerStrut Playlist is ready to go!”
If a user tries to add more than eight songs to a playlist, write them a message that their playlist will be rejected for being too long. You can write something like, “Too many songs!”
To check that it works, add another song to the array.
If there are less than eight songs in the playlist, let the user know that they should add more songs. You can write something like, “Add some songs!”
To check that it works, delete songs from the playlist.