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

Array methods (Sort, Reverse, IndexOf) in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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}?
ADo nothing
BReverse it to <code>{2, 4, 1, 3}</code>
CReturn the index of 3
DSort it to <code>{1, 2, 3, 4}</code>
What does Array.Reverse() do to {"a", "b", "c"}?
A<code>{"c", "b", "a"}</code>
B<code>{"a", "b", "c"}</code>
C<code>{"b", "a", "c"}</code>
D<code>{"a", "c", "b"}</code>
What does Array.IndexOf(array, value) return if value is not in the array?
A1
B-1
C0
DThrows an error
Which method would you use to find the position of the number 5 in an array?
AArray.IndexOf()
BArray.Sort()
CArray.Reverse()
DArray.Clear()
After calling Array.Sort() on {"dog", "cat", "bird"}, what is the order?
A<code>{"bird", "dog", "cat"}</code>
B<code>{"dog", "cat", "bird"}</code>
C<code>{"bird", "cat", "dog"}</code>
D<code>{"cat", "dog", "bird"}</code>
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.