Objects - Arrays Flashcards
What is an array?
A numbered list of items.
What is an index?
It is an item’s number in the array.
What will the sixth item on a list’s index be?
- Remember that we use 0 based counting in OOP.
How do you create an array?
1 - specify the type of data that you want to store in the array (string, int etc)
#2 follow the type declaration with square brackets : string[]
What will be returned if you dont tell the array what you want the items to contain?
null in each indices that hasn’t been assigned a value.
How do you assign values to specific indices?
arrayName[index # you want to assign] = “Value you want to give it.”;
favThings [0] = “First item.”; will assign “First item.” to the first indices.
How do you shorten the syntax of array creation?
You can shorten it to this:
string[] nameOfArray = {“first”, “second”, “third”};
How can you find out the length of an array?
nameOfArray.Length
What is a turnairy if statement?
Its a bit of syntactic sugar that combines an if/else into one statement:
return(pathStep , _path.Length) ? _path[pathStep] : null;
put a question mark after the conditions, separate the if and else with a :