C. You must use Console.WriteLine(nums.Sort()); instead.
D. The array must be converted to a list before sorting.
Solution
Step 1: Identify method call error
Arrays in C# do not have an instance method called Sort(). Sorting is done via the static method Array.Sort(array).
Step 2: Understand correct usage
The correct way is Array.Sort(nums); to sort the array in place.
Final Answer:
Arrays don't have a Sort() instance method. -> Option A
Quick Check:
Use Array.Sort(array), not array.Sort() [OK]
Hint: Array.Sort is static; no instance Sort() method [OK]
Common Mistakes:
Calling Sort() directly on array instance
Confusing List.Sort() with Array.Sort()
Trying to print Sort() return value
5. Given the array int[] values = {5, 3, 8, 3, 9};, which code snippet finds the index of the first occurrence of the number 3 and then reverses the array?
hard
A. int index = Array.FindIndex(values, 3);
Array.Sort(values);
B. int index = values.IndexOf(3);
Array.Reverse(values);
C. int index = Array.IndexOf(values, 3);
Array.Reverse(values);
D. int index = Array.IndexOf(values, 3);
Array.Sort(values);
Solution
Step 1: Find index of first 3
Array.IndexOf(values, 3) correctly returns the first index where 3 appears, which is 1.
Step 2: Reverse the array
Array.Reverse(values); reverses the array in place as required.
Final Answer:
int index = Array.IndexOf(values, 3);
Array.Reverse(values); -> Option C
Quick Check:
IndexOf + Reverse = int index = Array.IndexOf(values, 3);
Array.Reverse(values); [OK]
Hint: Use Array.IndexOf(array, value) to find index [OK]
Common Mistakes:
Using instance method IndexOf on array (not valid)
Confusing FindIndex with IndexOf
Sorting instead of reversing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.