0
0
C Sharp (C#)programming~5 mins

Array indexing and access in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the starting index of arrays in C#?
Arrays in C# start indexing at 0. This means the first element is at index 0, the second at index 1, and so on.
Click to reveal answer
beginner
How do you access the third element of an array named numbers?
You access it using numbers[2] because indexing starts at 0.
Click to reveal answer
intermediate
What happens if you try to access an index outside the array bounds in C#?
You get a System.IndexOutOfRangeException error because the index is invalid.
Click to reveal answer
beginner
How can you find the length of an array named items?
Use items.Length to get the number of elements in the array.
Click to reveal answer
beginner
Explain how to change the value of the first element in an array colors to "red".
Assign the new value using colors[0] = "red"; to update the first element.
Click to reveal answer
What is the index of the last element in an array with 10 elements?
A9
B10
C0
D11
Which of the following accesses the second element of an array named arr?
Aarr[2]
Barr[1]
Carr[0]
Darr[3]
What property gives the number of elements in a C# array?
ALength
BCount
CSize
DCapacity
What error occurs if you try to access array[10] when the array has 10 elements?
ANullReferenceException
BInvalidOperationException
CArgumentException
DIndexOutOfRangeException
How do you change the value of the first element in an array named data?
Adata.change(0, newValue);
Bdata[1] = newValue;
Cdata[0] = newValue;
Ddata.set(0, newValue);
Describe how array indexing works in C# and how to access elements safely.
Think about how you count positions starting from zero.
You got /4 concepts.
    Explain how to update an element in a C# array and what happens if you try to access an invalid index.
    Consider what happens if you try to open a door that doesn't exist.
    You got /2 concepts.