Recall & Review
beginner
What does the
Array.Sort() method do in C#?It arranges the elements of an array in ascending order (from smallest to largest).
Click to reveal answer
beginner
How does
Array.Reverse() affect an array?It reverses the order of the elements in the array, so the last element becomes first and the first becomes last.
Click to reveal answer
beginner
What does
Array.IndexOf(array, value) return if the value is not found?It returns
-1 to indicate the value is not present in the array.Click to reveal answer
beginner
Can
Array.Sort() be used on arrays of strings in C#?Yes, it sorts strings alphabetically (lexicographically) in ascending order.
Click to reveal answer
beginner
If you want to find the position of the first occurrence of a value in an array, which method do you use?
Use
Array.IndexOf() to get the index of the first matching element.Click to reveal answer
What will
Array.Sort() do to the array {3, 1, 4, 2}?✗ Incorrect
Array.Sort() arranges elements in ascending order.What does
Array.Reverse() do to {"a", "b", "c"}?✗ Incorrect
It reverses the order of elements.
What does
Array.IndexOf(array, value) return if value is not in the array?✗ Incorrect
Returns -1 to show the value was not found.
Which method would you use to find the position of the number 5 in an array?
✗ Incorrect
Array.IndexOf() finds the index of a value.After calling
Array.Sort() on {"dog", "cat", "bird"}, what is the order?✗ Incorrect
Strings are sorted alphabetically in ascending order.
Explain how you would use
Array.Sort(), Array.Reverse(), and Array.IndexOf() in a C# program.Think about sorting a list, then reversing it, and searching for an item.
You got /3 concepts.
What happens if you try to find the index of a value that does not exist in the array using
Array.IndexOf()?Consider how to check if a value is missing.
You got /3 concepts.